News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
A2P 10 DLC SMS - Batch Error 401 errorCode: AGW-402 and Delivery error 429
Tags: rest api
Nov 23, 2020 at 11:22am   •   5 replies  •  0 likes
Bob Mulvey


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

5 Answers
answered on Nov 24, 2020 at 5:47am  

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.


 0
on Nov 24, 2020 at 7:55am   •  0 likes

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;


on Nov 24, 2020 at 8:29am   •  0 likes

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

on Nov 24, 2020 at 9:43am   •  0 likes

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

on Nov 24, 2020 at 10:00am   •  0 likes

OK, thank you. Understood.

answered on Nov 23, 2020 at 2:08pm  

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?


 0
answered on Nov 23, 2020 at 1:31pm  

 0
on Nov 23, 2020 at 1:49pm   •  0 likes

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

answered on Nov 23, 2020 at 1:30pm  

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


 0
answered on Nov 23, 2020 at 2:22pm  


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.


 0



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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us