Twilio Channel - SMS 60200 Invalid parameter error (400 bad request)

Viewed 1114

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.

3 Answers

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

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.

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
});
Related