> For the complete documentation index, see [llms.txt](https://docs.mikopbx.com/mikopbx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mikopbx.com/mikopbx/english/faq/outbound-routing/add-p-preferred-identity-and-remote-party-id-header.md).

# Add P-Preferred-Identity and Remote-Party-ID header

Some providers require sending an additional SIP header when initiating an outgoing call. In this article we will describe a way to install it.

1. To solve the problem, additional contexts should be described through the **System File Customization** menu.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2Fn06cIfMIqk6wJhcxD3gW%2FSystemFileCustomization.png?alt=media&amp;token=4edfbfbf-6903-46c5-b1b5-d2a62131f59e" alt=""><figcaption><p>System File Customization menu</p></figcaption></figure>

2. We will edit the **extensions.conf** file.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FNuELWVzuFh5rThr08jvu%2FEditExtensions.conf.png?alt=media&amp;token=567dc075-00ed-45a7-bc10-915ccc1dc97f" alt=""><figcaption><p>Extensions.conf file</p></figcaption></figure>

3. Add the following text to the end of the file:

```php
[SIP-TRUNK-A2DDBADA-outgoing-custom]
exten => _X!,1,Dial(PJSIP/${number}@${PROVIDER_ID},600,${DOPTIONS}TKU(dial_answer)b(dial_create_chan_${PROVIDER_ID}_custom,s,1))
    same => n,ExecIf($["${DIALSTATUS}" = "ANSWER"]?Hangup())
    same => n,ExecIf($["${DIALSTATUS}" = "BUSY"]?Busy(2))
    same => n,return
    
[dial_create_chan_SIP-TRUNK-A2DDBADA_custom] 
exten => s,1,Gosub(lua_${ISTRANSFER}dial_create_chan,${EXTEN},1)
    same => n,Set(pt1c_is_dst=1) 
    same => n,Set(OUTGOING_CID=32672293042)
    same => n,ExecIf($["${OUTGOING_CID}x" != "x"]?Set(PJSIP_HEADER(add,P-Preferred-Identity)=<sip:${OUTGOING_CID}@127.0.0.1>))
    same => n,ExecIf($["${OUTGOING_CID}x" != "x"]?Set(PJSIP_HEADER(add,Remote-Party-ID)=<sip:${OUTGOING_CID}@127.0.0.1>))
    same => n,Set(__PT1C_SIP_HEADER=${UNDEFINED}) 
    same => n,Set(CHANNEL(hangup_handler_wipe)=hangup_handler,s,1) 
    same => n,return
```

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FQDoudGBqY5rjZEkn5ArS%2FCodeForExtensionsConf.png?alt=media&amp;token=9682d777-81ce-47b9-a7ee-154c948c44b1" alt=""><figcaption><p>Code for extrensions.conf</p></figcaption></figure>

{% hint style="danger" %}
**Pay attention:**

1. Replace all occurrences of "**SIP-TRUNK-A2DDBADA**" with your provider ID. You can find it in the browser address bar when editing the provider account in the MikoPBX web interface.
2. Instead of **"**[**sip:${OUTGOING\_CID}@127.0.0.1**](https://sip:$%7BOUTGOING_CID%7D@127.0.0.1)**"**, the required header value should be set
3. The provider ID format depends on the MikoPBX version: current versions use `SIP-TRUNK-XXXX`, older ones use `SIP-PROVIDER-XXXX` or `SIP-XXXX`. That is why the example does not extract the provider from the context name but takes it from the `${PROVIDER_ID}` variable, which MikoPBX sets before calling the context. Versions earlier than 2024.1.114 do not set this variable — replace `${PROVIDER_ID}` with your provider ID explicitly.
   {% endhint %}

#### When using the "User Groups" module:

```php
[SIP-TRUNK-A2DDBADA-outgoing-ug-custom]
exten => _X!,1,Dial(PJSIP/${number}@${PROVIDER_ID},600,${DOPTIONS}TKU(dial_answer)b(dial_create_chan_custom,s,1))
	same => n,ExecIf($["${DIALSTATUS}" = "ANSWER"]?Hangup())
	same => n,ExecIf($["${DIALSTATUS}" = "BUSY"]?Busy(2))
    same => n,return
    
[dial_create_chan_custom] 
exten => s,1,Gosub(lua_${ISTRANSFER}dial_create_chan,${EXTEN},1)
    same => n,Set(pt1c_is_dst=1) 
    same => n,Set(GR_VARS=${DB(UsersGroups/${FROM_PEER})}) 
    same => n,Set(tmpName=${CUT(GR_VARS,\,,2)})
    same => n,Set(tmpName=${CUT(tmpName,\_,3)})
	same => n,ExecIf($["${GR_VARS}x" != "x"]?Exec(Set(${GR_VARS}))) 
	same => n,ExecIf($["${GR_PERM_ENABLE}" == "1" && "${GR_ID_${tmpName}}" != "1"]?return) 
	same => n,ExecIf($["${GR_PERM_ENABLE}" == "1" && "${GR_CID_${tmpName}}x" != "x"]?MSet(GR_OLD_CALLERID=${CALLERID(num)},OUTGOING_CID=${GR_CID_${tmpName}}))
	same => n,ExecIf($["${OUTGOING_CID}x" != "x"]?Set(PJSIP_HEADER(add,P-Preferred-Identity)=<sip:${OUTGOING_CID}@127.0.0.1>))
	same => n,ExecIf($["${OUTGOING_CID}x" != "x"]?Set(PJSIP_HEADER(add,Remote-Party-ID)=<sip:${OUTGOING_CID}@127.0.0.1>))
    same => n,Set(__PT1C_SIP_HEADER=${UNDEFINED}) 
    same => n,Set(CHANNEL(hangup_handler_wipe)=hangup_handler,s,1) 
    same => n,return
```

{% hint style="warning" %}
The peculiarity of this option is that the value "OUTGOING\_CID" will be taken from the settings of user groups. For each group, you can assign your own value of the outgoing caller id. For example, the Westcall provider thus allows you to control the value of the callerid that the client sees.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mikopbx.com/mikopbx/english/faq/outbound-routing/add-p-preferred-identity-and-remote-party-id-header.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
