API Connector : Authorization Fail

Hi. I need help on bubble api connector. I am trying to connect to a warehouse API. I am stuck at the first call, “authentication/authorization” to get the Bearer token.

Below is the error produced when I tried to initialize.

“…client credentials are invalid…” . According to the warehouse tech support, the credentials are correct and they have done testing on their own when I raised the issue to them, so it must be me missing out something here. Below are my settings;

What I have tried so far;

  1. Replaced Username with just [api key] (no password).
  2. Replaced Username with Basic [api key] (no password).
  3. Authorization call header;
    3.1 Authorization value = [api key], with and without Content-Type
    3.2 Authorization value = Basic [api key], with and without Content-Type
  4. Authorization call body;
    4.1 only agent_id parameter and value
    4.2 agent_id, user_name, password parameters with their values.

Anybody can help me?

Below are the example for the warehouse api documentation.


  1. Authentication

Request path:

POST

http://warehouse.worldsyntech.com/api.php?route=rest/admin_security/api_login&grant_type=client_credentials

Screenshot 2020-12-13 at 2.36.57 PM Screenshot 2020-12-13 at 2.37.05 PM

Request Method:POST
Request ContentType:application/json

Example:

Response Json

Success response

{

“Success”: “1”,
“Error”: [],
“Data”: {“access_token”: “7a2cca74179ce5fa2fbeaea30cb9889575b9788d”,
“expires_in”: “262800”,
“token_type” : “Bearer”

}

}

Fail response

{

“Success”: “0”,
“Error”: [“client credentials were not found in the headers or body”],
“Data”: []

}

Sample code (php)

$api_key =”d8jesu81239fd==21jab”;

$request_body= array ();
$request_body [ user_name ] = “cust_123”;
$request_body [ ‘password’ ] = “password123”;

$request_body [ agent_id ] = “CJ1”;

// INITIALISE CURL
$ch = curl_init (“http://warehouse.worldsyntech.com/api.php?route=rest/admin_security/api_login&grant_type=client_credentials”);

header ( ‘Content-Type: application/json’ );
$post = json_encode ($request_body); // Create JSON string from data ARRAY
$authorization = "Authorization: Basic " . $api_key; // Prepare Autorisation Token
curl_setopt ($ch, CURLOPT_HTTPHEADER , array ( ‘Content-Type: application/json’ , $authorization)); // Inject Token into Header
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST , “POST” );
curl_setopt ($ch, CURLOPT_RETURNTRANSFER , true );
curl_setopt ($ch, CURLOPT_POSTFIELDS , $post);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION , 1);
$result = curl_exec ($ch);
curl_close ($ch);

$authorization_result = json_decode ($result, true );

if($authorization_result[“success”])
{

$bearer_token = $authorization_result[ ‘data’ ][ ‘access_token’ ];

$expire_in = $authorization_result[ ‘data’ ][ ‘expires_in’ ];

}

Note for development:

  • Bearer token and expire date should be stored in client system for sub sequence use so that client need not to query for authentication each time when making API call.
  • Before requesting for bearer token, check whether the bearer token stored in client system has expired, if no, can continue using the bearer token for calling other APIs, otherwise, execute the sample code above to request for new bearer token and store it.