question

ken-nye6499 avatar image
ken-nye6499 asked ken-nye6499 commented

Bulk SMS Production App getting 400 bad request using powershell

I think I have something wrong with the formatting of the body. this is my code and my error


Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

At C:\PowerShell\Txt_Bulk.ps1:38 char:16



$Token = Get-RingCentralAuthentication

$Bearer = $Token.access_token

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

"authorization" = "Bearer $Bearer"

}


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

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

$AuthBodyTxt = @{

"from" = '+14085555555'

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

"messages" = @{"to" = '+18315555555' }

}

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

$requesttxt = Invoke-RestMethod -Method Post -Uri $UriTxt -Headers $Header -Body $AuthBodTxt

return $requesttxt

high-volume sms
1 |3000

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 Phong Vu commented

The "messages" is an array of object and the "to" number is also an array of phone numbers. Right now, only one phone number per "to" array as we don't support group message yet.

"messages": [
    {
      "to": ["+14155550100"],
      "text": "Hello Alice"
    },
    {
      "to": ["+12125550100"],
      "text": "Hello Bob"
    }
  ]

https://developers.ringcentral.com/guide/messaging/sms/high-volume/sending-highvolume-sms#http

2 comments
1 |3000

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

mallabon avatar image mallabon commented ·

We have the same 400 error issue with PHP app after updating SDK to current version. I submitted a ticket Friday morning but no response yet. Is that something you can check? Client ID J6Vf4T1PRGeFpKip9qm-nw

0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ mallabon commented ·

This is a different topic. Don't ride on other thread like this. Ask in a separate question instead.

0 Likes 0 ·
ken-nye6499 avatar image
ken-nye6499 answered

Thanks for the reply , I think Im having trouble because Powershell ConvertTo-JSON is not adding the square brackets.

How do I make my code formatted like yours?



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

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

$AuthBodyTxt = @{"from" = "+14085555555";

"messages" = @{

"text" = "Hello Team testing";

"to" = "+18315555555"

}

}

$UriTxt = $AuthAPITxt.endpoint + $AuthAPITxt.url

$requesttxt = Invoke-RestMethod -Method post -Uri $UriTxt -Headers $Header -Body ($AuthBodyTxt|ConvertTo-JSON)>

when I test the code output I get this, will not having the square brackets cause the 400 request?
$AuthBodyTxt | ConvertTo-JSON

{

"messages": {

"text": "Hello Team testing",

"to": "+18315555555"

},

"from": "+14085555555"

}

1 |3000

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

ken-nye6499 avatar image
ken-nye6499 answered ken-nye6499 commented

I have figured out how to format the code, now Im getting a (503) Server Unavailable error. I am using the phone number that was provisioned for bulk SMS

 $AuthBodyTxt   = @{"from"     = "+14085555555";
                    "messages" = @(@{         
                                "text"     = "Hello Team testing";
                                "to" = @("+18315555555")
                                },
                                @{         
                                "text"     = "Hello Team testing";
                                "to" = @("+18315555555")
                                })
                    }

ConvertTo-Json -InputObject $AuthBodyTxt -Depth 3

{
    "messages":  [
                     {
                         "text":  "Hello Team testing",
                         "to":  [
                                    "+18315555555"
                                ]
                     },
                     {
                         "text":  "Hello Team testing",
                         "to":  [
                                    "+18315555555"
                                ]
                     }
                 ],
    "from":  "+14085555555"
}
25 comments
1 |3000

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 ♦♦ commented ·

What is your app client id?

BTW, If I were you, I would install one of the RC SDKs in a language that I know and can run on my local machine. Then copy paste the quick start code to run a quick test to make sure that my number and the app are setup correctly before trying own code like that.

0 Likes 0 ·
ken-nye6499 avatar image ken-nye6499 Phong Vu ♦♦ commented ·

I can use get and retrieve my messages I sent using the web interface, so I know that my credentials are correct. App client id 0BeUP9IIQCSuO-LdU9dXQw

0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ ken-nye6499 commented ·

I see 2 numbers were provisioned for HV SMS. (xxx) xxx-1306 assigned to extension 103, and (xxx) xxx-9720 assigned to extension 102. Which user do you login your app and which number do you use to send messages? It must be the owner of a number who can send messages from that number. So check and authenticate the app and use the number accordingly.


0 Likes 0 ·
Show more comments

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