Adding Custom Sipheaders using AMI Originate

I’m updating a script that uses AMI to originate calls but I’m having issues adding a custom sipheader (nothing exciting, we just need a client code). Much of the documentation I’ve found mentioned adding a SIPADDHEADERS variable but nothing seems to work. My current AMI action looks something like this (using the method mentioned at voip-info:

Action: Originate
Channel: Local/XXXXXXXXXX@from-internal
Context: OutVoice
Exten: s
Priority: 1
Variable: __SIPADDHEADER51=X-CLIENT: TESTCODE
ActionID: voic.24749

I’ve been using sngrep to watch my test calls and the X-CLIENT header just isn’t present. I’ve also attempted using __SIPADDHEADERS0. The machine in question is running Asterisk 13.38.1, which I’m unfortunately unable to update at this time. (long story). Does anyone know a method that would work with this version?

Are you actually using chan_sip (rather than the, currently supported, chan_pjsip), as I think this is specific to chan_sip.

Also this was a new one on me, and I suspect it is relying on implementation detail that is not part of the formal interface specification.

I would have done this by calling the technology driver specific add header function in the local channel.

Fortunately we are using chan_pjsip… so now that you mention it, using SIPADDHEADER likely wouldn’t work anyway! I’m not having much luck finding an AMI alternative to PJSIP_HEADER(which is generally what I’d use in dialplan).

This is kind of uncharted territory for me as well - I’ve never had issues assigning sipheaders from within the dialplan. To get around this, one thing I have tried is calling into a new context as laid out in this post. This causes other issues, as the AMI script’s originate action has quite a few other variable assignments attached, so I’d prefer avoiding this option if at all possible.

Regardless, you’ve given me a great place to start. Thank you so much for your reply!

Edit: Attempted using the following. No luck but hopefully I’m going in the right direction. Using PJSIP_HEADER as a variable feels odd but these are the only examples I’ve found so far.

Action: Originate
Channel: LOCAL/XXXXXXXXXX@from-internal
Context: OutVoice
Exten: s
Priority: 1
Variable: PJSIP_HEADER(add,X-CLIENT-CODE)=TEST
ActionID: voic.24749

I ended up resolving this by redirecting from a local channel to a new context within the dialplan and setting the sipheaders in there before sending out the dial explicitly after the originate.