twiliotwilio-apitwilio-click-to-calltwilio-programmable-voice

Ask Twilio to pass custom headers in webhooks


I'm using Twilio REST Api to create a call programmatically, with call-status and recordings web-hooks wired in. The web-hook POST requests are currently hitting the server but failing on me because there is a requirement for a custom header entry.

I want to be able to pass my custom headers (that needs to be sent in the upcoming web-hook request headers) when I create those calls with the web-hook urls. The custom header should have dynamic value.

I have something like this:

call = @client.calls.create(
          to: "+1XYZ",
          from: ENV['TWILIO_ACCESS_NUMBER'],
          twiml: '<Response><Record /></Response>', 
          status_callback: @@callStatusHandler,
          status_callback_event: ['answered', 'completed'],
        )

When I create such calls, I will have access to sessionid with a dynamic value, say my-session-value. Now when the webhook request comes in, I want sessionid = my-session-value in the header.

Is there a way to achieve this?


Solution

  • If you need to add your own custom headers, you can try to proxy your requests through some other logic before it hits your application servers. This was a past in the post around forking webhooks you can look at and see it it can be modified to meet your needs.

    Creating A Twilio Function to trigger 2 webhook endpoints (Autopilot & FrontApp) For Incoming SMS

    There is an example of passing a custom Axios HTTP header below:

    Make a Write Request to an External API using urlencoded data