Skip to main content

Authenticating

Your application needs to connect and authenticate with the API. You will receive a username and password from Active Ants to use with the API to get the token and the expiration date of this token. Please use this expiration date to cache the token locally to minimize token requests for better performance.

Create an HTTP POST request with the following fields:

  • grant_type (The grant_type is always “password” without the quotes)
  • username
  • password

The Content-Type needs to be application/x-www-form-urlencoded.

Below is an example of what the request should look like: Request:

POST /token HTTP/1.1
Host: shopapi.activeants.nl
Accept-encoding: gzip, deflate
User-Agent: Zend_Http_Client
Content-Type: application/x-www-form-urlencoded
Content-Length: 51

grant_type=password&username=shopapi-user&password=your-secret-is-safe

This request will return a JSON object with information on the success or failure of the request.

Example of a success response:

{
"access_token": "WW91IGNvdWxkIG5vdCByZXNpc3QgdGhlIHVyZ2UgdG8gbG9vayBjb3VsZCB5b3U/",
"token_type": "bearer",
"expires_in": 57599,
"userName": "shopapi-user",
"issued": "Wed, 18 Feb 2025 08:50:47 GMT",
"expires": "Thu, 19 Feb 2025 00:50:47 GMT"
}

Example of a failed response:

{
"error": "invalid_grant",
"error_description": "The user name or password is incorrect."
}

The parameters access_token and token_type need to be used in the header with every request you make to the API. The Authorization header looks like this:

Authorization: bearer WW91IGNvdWxkIG5vdCByZXNpc3QgdGhlIHVyZ2UgdG8gbG9vayBjb3VsZCB5b3U/

Please keep in mind that there is a space between token_type and access_token. In the next chapter, we will show you a complete example.

Validation: When your token expires or otherwise becomes invalid, any request you make to the API will be answered with a 401 error message:

{
"message": "Authorization has been denied for this request."
}

When this happens, we recommend you attempt to log in again up to three times before reporting an error in the connection and notifying Active Ants.