Mosukoshide
Mosukoshide

Reputation: 61

Adding extra information to the Twilio POST response

Is there an attribute I can add to the client.calls.create({ method which would allow me to add extra information to the request body that Twilio will post in the callback URL? Something like this:

client.calls.create({
                method: 'GET',
                extraInfo: { employeeID: 'ABC123' }, <-- This would be what I want to add to the JSON response.
                statusCallback: `${config.host}/completed`,
                statusCallbackMethod: 'POST',
                twiml: responseString,
                to: data.number`,
                from: `+1${availableNumbers[0]}`
            })

Would have Twilio return this to my callback URL:

{
  "extraInfo": { employeeID: 'ABC123' }, <-- This would be what should be added to the POST request
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "annotation": null,
  "answered_by": null,
  "api_version": "2010-04-01",
  "caller_name": null,
  "date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
  "date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
  "direction": "inbound",
  "duration": "15",
  "end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
  "forwarded_from": "+141586753093",
  "from": "+18668675310",
  "from_formatted": "(866) 867-5310",
  "group_sid": null,
  "parent_call_sid": null,
  "phone_number_sid": "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "price": "-0.03000",
  "price_unit": "USD",
  "sid": "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
  "status": "completed",
  "subresource_uris": {
    "notifications": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications.json",
    "recordings": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings.json",
    "feedback": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Feedback.json",
    "feedback_summaries": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/FeedbackSummary.json",
    "payments": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Payments.json"
  },
  "to": "+14155551212",
  "to_formatted": "(415) 555-1212",
  "trunk_sid": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json",
  "queue_time": "1000"
}

Upvotes: 1

Views: 111

Answers (1)

Alan
Alan

Reputation: 10781

Instead of using the twiml parameter, use the url parameter and append HTTP query parameters to the end of the URL. You can do the same with the statusCallback URL.

Passing Custom Information via Requests to Twilio

How to Share Information Between Your Applications

Upvotes: 1

Related Questions