PJSIP - set custom header from AGI


Recently I started porting my legacy system based on Asterisk 1.8 to 13 (certified).
In my setup, every call executes an AGI application and all is being processed there.
I have resolved most of my issues but setting a custom header from the application seems to be problematic.

Previously I used SIPAddHeader AGI commands but it seems to gone now so I’m trying setting the PJSIP_HEADER variable but I have no luck so far.

SET VARIABLE PJSIP_HEADER(add,P-Custom-Header)=HeaderValue

The example above gives an error like:
pbx_variables.c:1096 pbx_builtin_setvar: Set requires an ‘=’ to be a valid assignment.

Does anyone know what should be the right format?


according to:


I also tried:

SET VARIABLE PJSIP_HEADER(add,P-Custom-Header) HeaderValue

but that gives the same error.

I also tried to use EXEC

EXEC SET PJSIP_HEADER(add,P-Custom-Header)=HeaderValue

but no luck

another related thing is that I call Local channel to make an outbound call. When I try to add header directly in the dialplan I get error:

res_pjsip_header_funcs.c:520 func_write_header: This function requires a PJSIP channel.

The PJSIP_HEADER dialplan function operates on the channel it is executed on, this means you can’t use it on a Local channel. You have to use a pre-dial handler[1] from the Dial it is doing to execute the dialplan function on the dialed channel.

[1] https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers

1 Like