Please excuse our look. We're just getting started here.

Want to learn more about Twilio Forums? Check out our FAQ page here.

How to read headers in Twilio Functions?

edited August 2021 in Twilio Community

Hi guys.

I'm looking for some help, I'm trying to read headers from a SIP Call.

The call goes into a "Cisco UCCX/Finesse" service, then, it connects to Twilio using a SIP Domain, that's ready but now since we have an IVR at the UCCX service, we need to receive more options now inside Twilio so we're trying to use the headers.

Based on this post:

It should be possible to receive a Header in the following naming convention:
For example.

But, now I need to read that Header inside Twilio Functions, but I'm trying to do it locally first (to test it) based on this guide:

That is also linked to this guide:

I have this at the end:

"dependencies": {
    "@twilio/runtime-handler": "1.2.0-rc.3",
    "twilio": "^3.56.0"

But when I try to send a POSTMAN request with the above header (SipHeader_Test) or any header I receive that event.request is undefined so I can't read any header.

Maybe I'm doing something wrong or this works only inside the Console?

Thanks for your help!


  • Hi @asfo!

    This particular feature is currently still in preview and as a result still contains some issues including the one you discovered. Currently any header that contains an underscore in the key will be dropped.

    We have an engineer currently working on the fix and I'll post here once it's out. There shouldn't have to be any changes that you'll have to do after that and it should just be picked up on subsequent requests.

    Thank you for reporting this and trying out a new version :)

    Have a great weekend!

  • Also sorry I just realized that it didn't work for you locally either. Locally runtime-handler versions only get picked up with you use the latest version of @twilio-labs/plugin-serverless or twilio-run respectively.
    If you run twilio serverless:start -l debug or twilio-run -l debug respectively you should see a message logged along the lines of:

      twilio-runtime-handler:dev:server @twilio/runtime-handler version: 1.2.0-rc.3

    If that message is missing in your logs it means you have an old version of @twilio-labs/plugin-serverless or twilio-run respectively.

  • asfo
    edited August 2021

    Hi @Dominik Kundel thanks for your help.

    My @twilio-labs/plugin-serverless was out of date (the others were actually updated) and now it's working!.

    Just one last question, is it possible to make it works in production? I mean the guide explains that I can install the library in the Console, so it should work, is that right at the moment?

    We know that this is in preview mode, and it could have some issues, but we got an idea on redirect the SIP Headers from our own server to the Function, so we can remove the _ but just wondering if this library can work in production.

  • @asfo As Dominik said, the feature is currently in preview, so is being tested in private. This means it should become available soon, at which point we will release version 1.2.0 of @twilio/runtime-handler.

  • But yes @asfo in theory you could use it in production but we can't guarantee that there won't be breaking changes between the current rc version and the final release.

  • Just to follow up one more time here. @asfo we got the confirmation from the team that the issue has now been fixed in deployed Functions as well so you should start seeing headers containing _. If you already deployed they should just magically start showing up.

  • @Dominik Kundel that's amazing! I will move everything to the Functions then...Thank you very much!

  • @Dominik Kundel thank you again! I just debugged the event.request.headers and I see them 😀 I really appreciate your support and to all the engineering team!

If this is an emergency, please contact Twilio Support. This is not an official Support channel.
Have an urgent question?
Please contact Twilio Support. This is not an official Support channel.
Contact Support