Twillio and Webhooks

I’m trying to pass the TO and FROM phone numbers using the data filed in Particle.publish and webhooks.
Below is what I have but I get an error 21602Message body is required.

I tried different options but nothing seems to work and I can only get it working by specifcing the TO and FROM using the form as shown here https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-particle-photon

  sms = String::format("{\"From\": %s, \"To\": %s, \"Body\": \"body\"}",setEmailString.c_str(), setPhoneString.c_str());
      Particle.publish("twilio_sms", sms, 60, PRIVATE);
{
    "event": "twilio_sms",
    "url": "https://api.twilio.com/2010-04-01/Accounts/****************************/Messages",
    "requestType": "POST",
    "noDefaults": true,
    "rejectUnauthorized": true,
    "json": {
        "data": "{{{PARTICLE_EVENT_VALUE}}}"
    },
    "auth": {
        "username": "************************",
        "password": "***********************"
    }
}

Not sure if this will solve your problem but you need to wrap your %s placeholders in escaped double quotes too.

  sms = String::format("{\"From\": \"%s\", \"To\": \"%s\", \"Body\": \"body\"}",setEmailString.c_str(), setPhoneString.c_str());

You can even stick with Form over JSON.
For that you’d just pass {{{To}}}, {{{From}}} and {{{Body}}} instead of the hardcoded numbers and the entired event data {{{PARTICLE_EVENT_VALUE}}} as body into the respective form fields.

3 Likes

@ScruffR
Perfect, it works!

I didn’t know you can pass specific values. Thanks for the tip!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.