What's the correct way to set a pjsip header with lua?

I’ve tried setting a header with the following line. It’s not working:

channel.PJSIP_HEADER("add", "X-Dialed-Number"):set("8005550199")

Very few people use LUA, and the documentation on writing dialplan subroutines in LUA seems incomplete. However, are you running this code in the pre-dial subroutine?

Also note that only example I can find of setting a channel variable does not use :set.

1 Like

Thank you for the reply. Yeah I know, I made a mistake choosing pbx_lua for this project, but here we are…

This issue actually wasn’t a lua issue at all. Your answer, while unrelated, did get me thinking differently and I solved it.

According to the PJSIP_HEADER docs, setting the header will affect the incoming channel, not outgoing. You have to use a subroutine (gross).

Here’s what’s working for me. I hope someone in the future finds this helpful:

extensions = {

    ["test_context"] = {
        ["s"] = function (c, e)        

    ["pjsip_handler"] = {

        ["addheader"] = function (c, e)
            channel.PJSIP_HEADER("add", channel.ARG1:get()):set(channel.ARG2:get())  
            return app['return']()


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