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
AGW-402Invalid Authorization header
Tags: developer sandbox
Jan 6, 2022 at 1:47pm   •   6 replies  •  0 likes
ken-nye

I just signed up for the Bulk SMS API and I created a sandbox app . Im trying to send a bulk message, but Im getting and error authenticating. Any help would be appreciated

$SessionUser = "147050xxxxxx"

$SessionPassword = "j7MW2smk6xxxxxxx"

$ClientID = "-ihX9Qf4RPmdxxxxxxxx"

$ClientSecret = "TVH242ElR8iVs4LSTVSRn6xxxxxxx"

$ClientCredsPlainText = $ClientID + ":" + $ClientSecret

$ClientCredsBase64 = [System.Convert]::ToBase64String(

[System.Text.Encoding]::UTF8.GetBytes($ClientCredsPlainText))

$AuthHeader = @{"Content-Type" = 'application/x-www-form-urlencoded'

"accept" = 'application/json'

"authorization" = "Basic $ClientCredsBase64" }

$AuthAPI = @{"endpoint" = 'https://platform.devtest.ringcentral.com/'

"url" = 'restapi/v1.0/account/~/a2p-sms/batches' }

$AuthBody = @{

"from" = '+14705025555';

"text" = 'Hello Team testing API, no need to reply';

"messages" = @{

"to" = '+18313595555' }

}


6 Answers
answered on Jan 7, 2022 at 1:18pm  

now I have the app in production, I just changed the credentials and now I get this response.


Invoke-RestMethod : {

"error" : "invalid_grant",

"errors" : [ {

"errorCode" : "OAU-140",

"message" : "Invalid resource owner credentials"

} ],

"error_description" : "Invalid resource owner credentials"

}





 0
answered on Jan 7, 2022 at 1:26pm  

I figure mine out, the account number listed on the Production app is our main 800 number, but If I switch to the number I use to login, it works.


 0
answered on Jan 7, 2022 at 1:20pm  


Function Get-RingCentralAuthentication {

$SessionUser = "+18005555555"

$SessionPassword = "j7MW2sxxxxxxx"

$ClientID = "0BeUP9IIQxxxxxxxx"

$ClientSecret = "ufbjkdKNSCK3_HxCii8ZYgaeyxxxxxxx"

$ClientCredsPlainText = $ClientID + ":" + $ClientSecret

$ClientCredsBase64 = [System.Convert]::ToBase64String(

[System.Text.Encoding]::UTF8.GetBytes($ClientCredsPlainText))

$AuthHeader = @{"Content-Type" = 'application/x-www-form-urlencoded'

"accept" = 'application/json'

"authorization" = "Basic $ClientCredsBase64" }

$AuthAPI = @{"endpoint" = 'https://platform.ringcentral.com/'

"url" = 'restapi/oauth/token' }

$AuthBody = @{"grant_type" = 'password'

"username" = $SessionUser

"password" = $SessionPassword }

$uri = $AuthAPI.endpoint + $AuthAPI.url

$request = Invoke-RestMethod -Method POST -Uri $uri -Headers $AuthHeader -Body $AuthBody

return $request

}


 0
answered on Jan 6, 2022 at 2:38pm  

Thank you for the answer, to answer back
1. I prefer to use Powershell install of PHP
2. I was able to the Token working and got to the need for permissions. I will post my code below for anyone else trying to make this work
3. I sent in a support ticket to get upgraded to production


Function Get-RingCentralAuthentication {

$SessionUser = "xxxxxx"

$SessionPassword = "xxxx"

$ClientID = "-xxxxx"

$ClientSecret = "xxxxx"

$ClientCredsPlainText = $ClientID + ":" + $ClientSecret

$ClientCredsBase64 = [System.Convert]::ToBase64String(

[System.Text.Encoding]::UTF8.GetBytes($ClientCredsPlainText))

$AuthHeader = @{"Content-Type" = 'application/x-www-form-urlencoded'

"accept" = 'application/json'

"authorization" = "Basic $ClientCredsBase64" }

$AuthAPI = @{"endpoint" = 'https://platform.devtest.ringcentral.com/restapi'

"url" = '/oauth/token' }

$AuthBody = @{"grant_type" = 'password'

"username" = $SessionUser

"password" = $SessionPassword }

$uri = $AuthAPI.endpoint + $AuthAPI.url

$request = Invoke-RestMethod -Method POST -Uri $uri -Headers $AuthHeader -Body $AuthBody

return $request

}

$Token = Get-RingCentralAuthentication

$Bearer = $Token.access_token

$Header = @{"accept" = 'application/json'

"authorization" = "Bearer $Bearer"

}


$AuthAPI = @{"endpoint" = 'https://platform.devtest.ringcentral.com'

"url" = '/restapi/v1.0/account/~/a2p-sms/batches' }

$AuthBodyTxt = @{

"from" = '+155555555555';

"text" = 'Hello Team testing API, no need to reply';

"messages" = @{

"to" = '+15555555555' }

}

$UriTxt = $AuthAPI.endpoint + $AuthAPI.url

$requesttxt = Invoke-RestMethod -Method Post -Uri $UriTxt -Headers $header -Body $AuthBod

return $requesttxt



 0
answered on Jan 6, 2022 at 2:31pm  

First of all, what prevents you from using the RingCentral PHP SDK, which is much more convenient for you to get authenticated and to call APIs?

Second, you need to authenticate (login) to get an access token, then use the access token to call an endpoint. In your code, I don't see you call the POST /restapi/oauth/token to get the access token at all. See Authentication reference at the Password Flow section to learn more.

Third, the High Volume SMS API is not supported under sandbox environment. You need to have a production account and send a support request with your app client id so that they can help to graduate your app to the production and you can run test on your production environment.


 0
answered on Jan 6, 2022 at 1:47pm  

this is the response

Invoke-RestMethod : {

"errorCode" : "AGW-402",

"message" : "Invalid Authorization header",

"errors" : [ {

"errorCode" : "AGW-402",

"message" : "Invalid Authorization header"

} ]

}


 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