Authentication
In this section, you will learn how to properly access the API via API login and password.
To start working with the API, you must have an API login and password (don't confuse login and password from mobile-calendar account).
- 1.
- 2.Go to Synchronization > Rest API.
- 3.At this point, you receive your login details.
The API uses the underlying HTTP authentication scheme. You must include an Authorization header with each mobile-calendar API query.
Authorization: Basic {username:password}
The following script gets prices for the date range 1/1/2021 - 1/31/2021.
Including the header is visible on line 10.
function sampleRequest()
{
define(USERNAME, '[email protected]************************');
define(PASSWORD, 'SJbVx^[email protected]*****************************');
$url = 'htttps://api.mobile-calendar.com/get/pricing';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, USERNAME. ":" .PASSWORD);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"from" => "2021-01-01",
"to" => "2021-01-31"
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ['body' => $result, 'httpcode' => $httpcode];
}
Remember to add a header:
Content-Type: application/json
The authorization error returns the error code 401 Unauthorized and the JSON response shown below:
{
"status": "error",
"errors": "Wrong credentials"
}
- Make sure your request includes an Authorization header
- Make sure that you have entered the correct login credentials (API login and password)
- Make sure you have entered a valid URL
You have a problem? contact us: [email protected]
Last modified 4mo ago