How to add sip header to incoming call?


Have been going around the forum + web for some days now about that small issue.
I am trying to add a custom header on the invite that is sent to sip phone was a call comes in.

Basically the purpose is so the phone can take the details from the INVITE and issue a command to open a webpage.

tried to add in custom_extensions.conf:

exten => s,1,SIPAddHeader(X-Access-URL=“”)
exten => s,n,Return

and tried to put in the “default” trunk’s Asterisk Trunk Dial Options:

and also in the advanced settings -> Asterisk Dial Options:

None of these managed to add the header though :frowning: (Checked on asterisk cli + on wireshark on the receiving machine)

I am using FreePBX 14 & Asterisk 13

Please Advise.


That approach should work, but it might be easier to define a custom inbound context and use it like the ‘from-pstn-e164-us’ context in extensions.conf. Define the context and send the incoming call to is, then have the context ‘goto’ to the ‘from-pstn,s,1’ context and step.

IMO, none of the approaches mentioned will work, because Asterisk passes only a few specific headers from trunk to extension. So, instead of modifying headers received from the trunk, you must modify headers sent to the extension.

As a test, in extensions_custom.conf, try adding:

exten => s,1,SIPAddHeader(X-Access-URL: "")
exten => s,n,MacroExit()

Tried both approaches of @Stewart1 & @cynjut , didn’t seem to work… (AKA added:

exten => s,1,SIPAddHeader(X-Access-URL: “”)
exten => s,n,MacroExit()

& also tried to use define a custom context then send it back to from-pstn,s,1 with a goto)

Tried also to add [from-pstn-custom]
as it says on the extensions.conf “; create this context in extensions_custom.conf to include customizations”

Used @cynjut 's approach there didn’t work out as well.

@Stewart1 could you elaborate maybe on how asterisk know which headers to pass (as from what you say it seems it is filtering the headers or taking just specific ones…) or if you have another idea it is also most welcomed!

What is you are trying to do here exactly? You want to set custom headers on a call to your SIP phones so they can process them and open a web page?!

So does that means these are headers that the phone expects? The X-Access-URL you are trying to send, it is a header the phone can understand, parse and take action on?

I guess I’m trying to figure out why you’re doing all this at the phone level when it can be done at the Asterisk level.

I assume that (at least for testing), the Inbound Route points directly to an extension and the extension does not have Follow Me, call forwarding or any other special handling.

When you tried macro-dialout-one-predial-hook, what happened?

  1. The custom macro didn’t get executed?
  2. The macro got executed, but the custom header didn’t get added?
  3. The custom header got added, but the phone did not respond correctly?

Post a log showing the malfunction.

If it’s helpful, I wrote a guide on how to use dialplan hooks yesterday:

1 Like

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