Jump to content

Api Calls


techhelper1

Recommended Posts

Hi again,

 

I have been following the documentation to do remote API calls. How would I be able to do an array for the Users-Add call and others that would need an array at a remote location? Thanks.

 

Use

 

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args));

 

P.S. An SDK has been released that makes API requests much easier, but it only works for version 3.0.0.b4 and newer.

Link to comment
Share on other sites

  • 2 months later...

I'm not able to connect with the API. Using the files from SDK, following steps from your documentation, trying get and post, definitely correct user/key information.

 

message: 401 The authorization details given appear to be invalid.

 

I took your blesta_api.php and blesta_response.php as they are, created a new file and called the API the following way:

// of course I got the right informaiton in $api_url, $api_username and $api_key
$blesta_api = new BlestaApi($api_url, $api_username, $api_key);
// The Model to request, I tried here "users" as well
$model = "clients";
// The method to request, I tried here "get" as well
$method = "getByUserId";
// $format = "json" is set by your class
// All parameters to send, 3 is my test client
$params = array('user_id'=>3);
// API request
$response = $blesta_api->get($model, $method, $params);
return $response;

I took a look into the blesta core files api.php and api_keys.php and did some testing.

It seems that the getAuthMode() doesn't return a mode, both conditions return false. All requested $_SERVER variables return null.

I tested this by commenting out the condition for basic to force this mode and entering the correct key and url in line 2285/286 - then it works.

Link to comment
Share on other sites

Ok, I think I found the cause: My Server API is CGI/FCGI, not Apache 2.0 Handler.

http://stackoverflow.com/questions/3663520/php-auth-user-not-set

 

And inspired by this thread: https://github.com/symfony/symfony/issues/1813

I added this to my .htaccess:

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ api.php [QSA,L]
</IfModule>

now it works!! :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...