# Setting DIVERSION header using Lua

**URL:** <https://community.asterisk.org/t/setting-diversion-header-using-lua/105831>\
**Category:** Asterisk SIP\
**Created:** [December 13, 2024, 11:11am UTC](https://community.asterisk.org/t/setting-diversion-header-using-lua/105831 "2024-12-13T11:11:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladwoguer](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/vladwoguer/32/8203_2.png) [@vladwoguer](https://community.asterisk.org/u/vladwoguer)\
**Post date:** [December 13, 2024, 11:11am UTC](https://community.asterisk.org/t/setting-diversion-header-using-lua/105831/1 "2024-12-13T11:11:43Z")

</div>

Hi,  
I use PJSIP with Asterisk 20 and Lua. I would like to set DIVERSION header in the outgoing call.

When I am setting the DIVERSION header on the outgoing call for the first time it works as expected.

> channel[“PJSIP\_HEADER(add,Diversion)”]:set(channel[“diversion”]:get())

> VERBOSE[3191238] res\_pjsip\_logger.c: \<— Transmitting SIP request (1258 bytes) to UDP:_ **.** _.185.103:**60 —\>  
> INVITE sip:+#########35@server7:_60 SIP/2.0  
> Via: SIP/2.0/UDP ..124.63:60;rport;branch=z9hG4bKPj2cb686ba-7fb3-45e9-9241-f34cdb998848  
> From: “Asterisk BENCH” sip:+#########53@\*\*\*.\*\*\*.124.63;tag=e8e6024d-cf83-457a-8946-a6fd7550eaf9  
> To: sip:+#########35@server7  
> Contact: sip:+#########41@\*\*\*.\*\*\*.124.63:\*\*60  
> Call-ID: 19f4a147-bae3-4520-8d8d-11da035dd280  
> CSeq: 26838 INVITE  
> Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, INFO, MESSAGE, REFER  
> Supported: 100rel, timer, replaces, norefersub, histinfo  
> Session-Expires: 1800  
> Min-SE: 90  
> X-Asterisk-CallID: f18bec918f744b4425138a59a99e9ed6@._**.17.60  
> P-Asserted-Identity: “+#########53” sip:+#########53@\*\*\*.\*\*\*.17.60;user=phone;sc=server2;tag=da7296ffb710f1183eaf98869db51467  
> Diversion: sip:+########38@\*\*\*.\*\*\*.124.63;reason=unconditional  
> Max-Forwards: 70

However when I have an incoming DIVERSION header, even when I try to update the outcome of the INVITE is still showing the original.

I also tried:

> channel[“PJSIP\_HEADER(update,Diversion)”]:set(diversion\_value)

On the logs it is not updating the header.  
I am updating the DIVERSION header with the command above. I am using the Referred-By value, but as you see they do not match.

> Referred-By: sip:+########35@server7  
> Diversion: sip:+########38@\*\*\*.\*\*\*.124.63;reason=unconditional

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [December 13, 2024, 11:14am UTC](https://community.asterisk.org/t/setting-diversion-header-using-lua/105831/2 "2024-12-13T11:14:04Z")

</div>

You’re trying to manipulate things at the generic header level, and there is built in support for Referred-By/Diversion. You can’t manipulate that at the generic header level as it will be overwritten, unless you disable it on the endpoint by setting the “send\_diversion” option to “no”. I haven’t tested that though.

The built in support uses the REDIRECTING dialplan function[1].

[1] [Manipulating Party ID Information - Asterisk Documentation](https://docs.asterisk.org/Configuration/Functions/Manipulating-Party-ID-Information/?h=redirecting#redirecting-dialplan-function)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [January 12, 2025, 11:14am UTC](https://community.asterisk.org/t/setting-diversion-header-using-lua/105831/3 "2025-01-12T11:14:05Z")

</div>

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