Hello,
In our migration from another provider to RingCentral SMS, we increased the flow of SMS traffic though our RingCentral A2P 10DLC number in the last 24 hours.
When we did so we started seeing an increase in error 401's in our batch calls. Additionally, we are seeing an increase in delivery error 429 on your RingCentral server (especially when our traffic is at its peak).
We had to take the action of decreasing the traffic we are sending to your server (moving back to the previous provider) until we determine how to best resolve this.
We are using the Java implementation. I note that we are not keeping the session open and furthermore, we are not batching the sends (1 message per batch). It is implemented this way following your code example AND migrating from another provider's basic flow of control that we use.
Please see an example of the error 401 below.
Please advise, are we hitting a bug in your service or are we misusing the API ?
2020-11-23 13:43:45,855 [ERROR] Thread-541640 MessagingServiceImpl:64 RingCentral exception - com.envera.east.sms.notification.service.MessagingException: HTTP Response
=============
status code: 401
Server: nginx
Date: Mon, 23 Nov 2020 18:43:45 GMT
Content-Type: application/json
Content-Length: 175
Connection: keep-alive
WWW-Authenticate: Bearer realm="RingCentral REST API"
RCRequestId: d158ffb4-2dbb-11eb-860b-0050568dac6b
{
"errorCode" : "AGW-402",
"message" : "Invalid Authorization header",
"errors" : [ {
"errorCode" : "AGW-402",
"message" : "Invalid Authorization header"
} ]
}
HTTP Request
============
HTTP POST https://platform.ringcentral.com/restapi/v1.0/account/~/a2p-sms/batch
Authorization: Basic <Note: I deleted our token>
X-User-Agent: RC-JAVA-SDK Java 1.8.0_102 Windows Server 2012 R2
{"from":"19412634395"," <...deleted detail...>
Just thought I would give an update for the community. Phong helped me!
The issue for us was that we were being VERY inefficient in our implementation. We were re-authenticating for every send. At the rates we are sending this is not good. We did this simply because the prior implementation we had sort-of took us down that path (but that prior implementation was P2P using multiple numbers).
Instead, we will now use "restClient.autoRefresh()" in our java implementation's singleton that instantiates the RingCentral RestClient object.
At that point, we should be good to go. I will say though I wish there was a way for us to check to see if we were authenticated. I write this because in the case of misc error handling, I'd like to validate the authentication (just in cases it is somehow lost). If I was able to do this, it would allow me, in my error handling, to get a new token.
Hi Bob,
To check if the app is authenticated, you can rely on the token object from the restClient instance. Once you call the authorize(), the token object will have token info, otherwise, it is null. However, there is no guarantee that if the access token and the refresh token are still valid. If you turn on the auto refresh, you'll just rely on the SDK to use the refresh token to refresh and keep the access token valid while your singleton process is running. If something goes wrong with the auto refresh so the SDK cannot refresh the token, you will catch this error when trying to call an API "Auth exception: Refresh token has expired". So always wrap your API call around a try{} catch(){}
public class RestClient { public static final String SANDBOX_SERVER = "https://platform.devtest.ringcentral.com"; public static final String PRODUCTION_SERVER = "https://platform.ringcentral.com"; ... public TokenInfo token;
The auth will only get called 1 time in that suggestion.
If my batch send gets a 401 (like I am seeing now in the exception I provided in my initial post), and I do not take action on that possibility, then my code would not recover unless we restarted the application (which is a 24x7 application server ).
I want to trust "refresh", but can I really trust that once I call it I am not ever going to have to worry about the token needing to be be recreated? I see the following that worries me: https://community.ringcentral.com/questions/7503/java-sdk-subscription-refresh-causing-401-error.html
That is the RC PubNub subscription object. It's separated from the RestClient object but it uses the tokens from the RestClient.
OK, thank you. Understood.
I also don't understand your problem. You showed the authentication error below, which seemed you could not pass the authentication (login). How could you call the a2p/batch to send SMS?
{ "errorCode" : "AGW-402", "message" : "Invalid Authorization header", "errors" : [ { "errorCode" : "AGW-402", "message" : "Invalid Authorization header" } ] }
And where is the 401 and 429 errors?
I cannot send a Team messaging invite to this email address. Is your IT block this feature?
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder