REST API Authentication - 401 Unauthorised authentication failure

Updated 1 week ago

If you're getting this error, you're not using the correct authentication.

When using our REST API, Basic HTTP authentication should be used in the header. Our docs explain this here: https://developers.clicksend.com/docs/rest/v3/#authentication

Either:

username - Your API username

password - Your API key

You can get your API credentials by clicking 'API Credentials' on the top right of the dashboard.

OR

username - Your account username

password - Your account password

These are the same credentials that you use to login to the dashboard.

The Authorization header is constructed as follows:

  • Username and password are combined into a string "username:password"
  • The resulting string is then encoded using Base64 encoding
  • The authorization method and a space i.e. "Basic " is then put before the encoded string.

For example, if the user agent uses 'Aladdin' as the username and 'open sesame' as the password then the header is formed as follows:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

If you're not sure how to do this, you can use the online service http://base64encode.com

Curl example:

curl --include \
--header "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=" \
'https://rest.clicksend.com/v3/account'

Generate the Authentication header with code

PHP Authentication Header Example

"Authorization: Basic ".base64_encode($username.":".$password)


How Did We Do?