The supplied authentication is invalid
If you ever used Africa’s Talking API, this is a common error that you find.
It is really a pain and developers get frustrated because of it, I do too (trust me).
Before we go into that, let us first see how you can play around with the API.
When you have an account with AT, there is two ways that you can use our APIs: either on Sandbox or Live.
Sandbox is sort of a mirror of the live account. You can do almost everything on sandbox that you could have done on your live account. And the added advantage of sandbox is that, it is free; you are not charged for the tests that you do, or the transactions that you make, unlike on Live where you are charged for everything- yes, everything.
So The supplied authentication is invalid is a common error for us all. And I see it often. Our API authenticates your username and API key, should any of these be incorrect, then the error will keep popping up and give you hypertension.
So while on Sandbox, the username is always sandbox, and you have to generate the API key, from the Settings on the menu.
Once you have generated the key, give it at least 3 minutes before trying it in your application. It should work.
While on your live account, it is a bit complicated. This is because, on your live account you can have so many teams with different apps.
Each team has member(s), which has a different app name, a username, and hence a different API key.
Team: A team allows you to work collaboratively with other developers and monitor the activity of your application
Members: These are people in your team. You can assign them different levels of access.
App: This is what will be talking to the API. You can see how your app is doing, troubleshoot errors and manage your application through the dashboard.
Let me demonstrate this.
So should you be testing a particular app, make sure to be in the right team to get the username and generate the API key from there.
Sometimes the error keeps persisting if you are using the Direct URL. This could be because of using the wrong url.
Let us take an example of sending a message via URL.
While on sandbox, the URL will be : (notice the sandbox)
https://api.sandbox.africastalking.com/restless/send?username=myusername&Apikey=XXXX&to=+254711XXXYYY&message=We love code
While on your live account, the URL will be :
https://api.africastalking.com/restless/send?username=myusername&Apikey=XXXX&to=+254711XXXYYY&message=We love code
This should guide you and help you to fix the error, however, if it still persists make sure to get in touch with the Africa’s Talking team, either on Slack or Intercom and you will be assisted.