SIP Header Modification

Hi everyone,

I am sending a call from Server A (not asterisk) to an asterisk server and then back out to server A again. Server A generates a CDR for each call and Asterisk also generates a 2 CDR’s (Using Fork option), but I need to able to link all the CDR’s together.

Currently I have managed to extract the ‘Call-ID’ from the sip header generated by Server A and store it in the Asterisk CDR’s which is fine for the inbound flow and asterisk side, but when sending the call back out of Asterisk back to Server A it only stores the ‘Call-ID’ as received from Asterisk.

My thinking is the best option is in asterisk prior to the dial command, to set the ‘Call-ID’ in the Asterisk SIP header to the same id (or an amended version) of the original one stored. As the original Call-ID received is unique then this will be fine, but I cannot find a way of changing it from the default which is automatically generated for the call:


Does anyone know how to change this please? Or have any other suggestions of how I can tie up the CDR’s (bearing in mind the final ‘Server A’ only appears to store the Call-ID (as well as the dialed number etc))

PS. I have been looking at SIPAddHeaders, but obviously this is for adding, not editing/setting headers.

Thank you in advance for any help you can provide!

Call-ID is critical to the protocol. If it were possible to change it as an arbitrary SIP header, Asterisk would not recognize the responses to the INVITE, as they would not match what it sent. It would retransmit the INVITE until the maximum number of retries was reached, then drop the call.

In any case, none of the data structures needed to support a SIP call exist until after the Dial application has started running. In particular, that means there is no Call-ID to change at that point. There are no user intervention opportunities between calling Dial and getting back the response to the INVITE.


Yes of course, I completely missed/forgot about that, thank you!
In order to solve the problem of linking CDR records though, do you have any suggestions?

I guess, if it is possible to Log the Asterisk generated Call-ID to its CDR along with the previous Call-ID (as a variable carried forward) then I can match that to Server A’s CDR for the outbound call.

Can the asterisk Call-ID be captured though to its own CDR?