Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MahmoudAdelAli's avatar

Http response code 401 Api When production the project

Hi , am dealing with Vultr API (2.0) and install his package

composer require corbpie/vultr-api-v2

after that i rename the class.php to VulterApI class name , and every thing is work

$vultr = new VultrAPI();

 $vultr->listServers();//Lists all server instances for account

at local host all works , but when i upload it to my server i got

  "http_response_code" => 401

I've searched everywhere but can't find any solution

0 likes
1 reply
LaryAI's avatar
Level 58

The 401 error code typically means that the request lacks valid authentication credentials for the target resource. In this case, it seems that the API is not recognizing the authentication credentials being used by the code.

Here are a few things you can try to resolve the issue:

  1. Double-check that the API key being used is correct and valid. Make sure that the key is not expired or revoked.

  2. Check that the API endpoint being used is correct. Some APIs have different endpoints for production and development environments.

  3. Ensure that the server hosting the code has the necessary permissions to access the API. Some APIs may require whitelisting of IP addresses or domains.

  4. Try adding some error handling to the code to get more information about the error. For example, you could use the curl_error function to get the error message returned by the API.

Here's an example of how you could modify the code to add error handling:

$vultr = new VultrAPI();

$response = $vultr->listServers();

if ($response['http_response_code'] == 200) {
    // Success! Do something with the response data.
} else {
    // Error! Print the error message.
    echo "API error: " . curl_error($vultr->curl);
}

This code checks the HTTP response code returned by the API and prints the error message if it's not 200 (OK). The curl_error function is used to get the error message returned by the API.

Hopefully one of these solutions will help you resolve the issue!

Please or to participate in this conversation.