Skip to main content

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' }

}


this is the response

Invoke-RestMethod : {

"errorCode" : "AGW-402",

"message" : "Invalid Authorization header",

"errors" : [ {

"errorCode" : "AGW-402",

"message" : "Invalid Authorization header"

} ]

}


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.


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



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"

}






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

}


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.


Reply