Add P-Preferred-Identity header for outbound DID

Hi, I have been looking though all the other posts around this and it seems a few people have had similar issues. I am using Asterisk 16.28.0 running on Debian.

the documentation from my sip provider seems to only cover older version of asterisk and states to set the outbound CID to add the header with the following on the dialplan

SIPAddHeader(P-Preferred-Identity: <sip:[])

but after doing a lot of research I have discovered this will not work for PJSIP registrations and I should be using PJSIP_HEADER instead I have attempted this in a number of ways.

exten => _0X.,1,NoOp(Dialing external number)
same => n,Set(PJSIP_HEADER(add,P-Preferred-Identity)="<>")
same => n,Dial(PJSIP/+44${EXTEN:1}@SipgateTrunk)

I then seen people saying it needs to be done with option b so attempted this on my dial plan

exten => _0X.,1,NoOp(Dialing external number)
same => n,Dial(PJSIP/+44${EXTEN:1}@SipgateTrunk,,b(SetOutLine^Line^1))

exten => Line,1,NoOp(** Pre dial settings **)
same => n,Set(PJSIP_HEADER(add,P-Preferred-Identity)="<>")
same => n,Return()

I have also seen some comments with users using the same SIP provider in a different country saying not to use the < > around the but ever time I attempt to dial out the number used is the trunk default number.

I have also attempted to set “send_pai=no/yes” option in the endpoint section of the SIP providers config in PJSIP.conf without any affect. is there any other settings that I should consider. I am not creating complex dialplans currently as I want to ensure all features are working as expected before I add complexity. hence the statistic assigned header.

Any help with this would be greatly appreciated.



The I in DID stands for inbound, so an outbound DID is a contradiction.

The chan_sip version just set an inheritable channel variable behind the scenes, so can be done on the incoming channel. You need to use the second method for chan_pjsip, as the operation must be performed on the outbound channel, after it has been created.

P-Preferred-Identity is unknown to Asterisk, so send_rpid won’t help.

You haven’t provided “pjsip set logger on” type output, which would make it clear exactly which headers you are sending. You should do that. If it shows you are setting the header, then the issue isn’t with Asterisk (Asterisk will pass the content through as is, so if that is wrong for the provider, that is still really a provider issue). Basically the second method should work. Given they seem to expect a + for the destination number, it seems inconsistent to not use it for presentation number.

Similarly, the verbose log, at level 3 upwards, will tell you whether the SetOutLine context is actually being run.

The angle brackets are optional, for the URI in your example.

Have you checked whether the provider needs you to prove you own the number that you are using and that it is an acceptable format. In particular, you have provided it as though it had the international type of number. Are you sure that they don’t require either an initial + or the country exit code (00 for the UK)

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