Jake Posted March 31, 2020 Report Posted March 31, 2020 I'm having a problem connecting to the API. I have setup an API key and user. I am trying to connect to the API via the following code: $User = "my_user_Name"; $Key = "My_key"; $Url = "My_url"; $this->blestaapi->SetVariables($Url, $User, $Key); $Response = $this->blestaapi->get("users", "get", array('user_id' => 3)); print_r($Response->response()); print_r($Response->errors()); I had to change the API file just a bit because the way my application is setup to initialize the class before I can pass the username and key. So I created a setter method to do that. The Blesta API class now looks like this: public function __construct() {} public function SetVariables($url, $user, $key) { $this->url = $url; $this->user = $user; $this->key = $key; } When I run the app the error message I get is: stdClass Object ( [user] => stdClass Object ( [valid] => The API user or key appears to be invalid. ) ) I have verified that the object does in fact have the username and key with a var dump of the object. Any Ideas of what the problem could be? Quote
Tyson Posted March 31, 2020 Report Posted March 31, 2020 In Blesta, under Settings > System > API Access, you are sure you are using the correct user/key combination? Have you confirmed there are no unexpected spaces before/after either the user or the key? The error indicates there is no API user match between what you provided via the API SDK and what Blesta has stored in its database table `api_keys`. You can check that table to be sure the user/key are identical to what you are passing via the API. Quote
Jake Posted April 1, 2020 Author Report Posted April 1, 2020 I just verified that the username and key is correct and there are no additional spaces. Quote
Jake Posted April 1, 2020 Author Report Posted April 1, 2020 Also I verified that the credentials are working by excuting the code via command line. They work fine Quote
Jake Posted April 1, 2020 Author Report Posted April 1, 2020 I just tried in Postman to make sure it was not a problem in my code and it gives me the same things Quote
Jake Posted April 1, 2020 Author Report Posted April 1, 2020 Ok...That was a painful lesson. It turns out that that apache was running php as CGI/FastCGI. In order to make this work you will need to add the following to the .htaccess file SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0 Works great now. Tyson 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.