4

I'm getting a "400 - Bad Request" error with Twilio API, but couldn't find the reason.

Here's my request:

curl --location --request POST 'https://verify.twilio.com/v2/Services/xxxxxxxxxxxxxx/Verifications' \
--header 'Authorization: Basic xxxxxxxxx' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Channel=sms' \
--data-urlencode 'To=+44xxxxxxxxxx'

I'm getting the response:

{
    "code": 60200,
    "message": "Invalid parameter",
    "more_info": "https://www.twilio.com/docs/errors/60200",
    "status": 400
}

The response includes a RequestID header, but in the Twilio portal there is no way to lookup errors by RequestID.

Artemis
  • 2,553
  • 7
  • 21
  • 36
PiyushG
  • 41
  • 2

4 Answers4

1

Your example is not following the product documentation example listed below (which works):

https://www.twilio.com/docs/verify/api

curl -X POST https://verify.twilio.com/v2/Services/VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Verifications \
--data-urlencode "To=+15017122661" \
--data-urlencode "Channel=sms" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
Alan
  • 10,465
  • 2
  • 8
  • 9
  • Thanks Alan, what's the difference? Tried in the above format as well and same error message. – PiyushG Apr 18 '21 at 18:40
  • 2nd one works for me without any issues. So it sounds like based on the 4xx error, something wrong with the client side request. I am running cURL 7.64.1. – Alan Apr 18 '21 at 23:14
1

I solved my issue by using the SERVICE_SID instead of ACCOUNT_SID. Here is what my code looks like

import twilio from "twilio";

const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);
...
const { sid } = await client.verify.services.create({
      friendlyName: "My First Verify Service",
    });

const response = await client.verify.services(sid).verifications.create({
      to,
      channel: "call", // sms, call, or email
});
crispengari
  • 7,901
  • 7
  • 45
  • 53
0

I experienced the same error message even with correct parameters. I was using the account SID in the request URL, when it should be the service SID for the Verify service that was created.

Using the account SID in the url resolved the error for me.

Owen
  • 765
  • 9
  • 9
0

I've also encountered this issue, it appears to be some confusion in the twilio docs, however I did found a place in their docs that show the right way to set this up.

from the official docs https://www.twilio.com/docs/verify/quickstarts/node-express

The solution was to use the serviceSid and NOT the accountSid as it might suggested in some parts of the docs.

in the code it should look like this:

client.verify.v2.services(SERVICE_SID)

Please note that am accountSid is prefixed with AC (i.e. AC3265cbdh...) and a serviceSid is prefixed with VA (i.e. VA3265cbdh...)

as hard-coded in the example shown in the link above from the docs

Joe
  • 197
  • 1
  • 3