question

Bob Mulvey avatar image
Bob Mulvey asked ·

A2P 10 DLC SMS - Batch Error 401 errorCode: AGW-402 and Delivery error 429


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...>

api smsa2p sms
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered ·

Hi Bob, what is your email address? I am happy to jump on a call and assist you better.

1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Bob Mulvey avatar image
Bob Mulvey answered ·
1 comment
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I cannot send a Team messaging invite to this email address. Is your IT block this feature?

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered ·

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?

1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Bob Mulvey avatar image
Bob Mulvey answered ·


There are 2 problems here, not 1. that is why. The problems both increase as I increase flow rate from the old provider to new.

1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Bob Mulvey avatar image
Bob Mulvey answered ·

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.

4 comments
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

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;


0 Likes 0 ·

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

0 Likes 0 ·

That is the RC PubNub subscription object. It's separated from the RestClient object but it uses the tokens from the RestClient.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys