PJSIP headers in outbound calls

Hi all,
I need to read some SIP headers from an outbound call created with Dial dialplan command using PJSIP channel driver, but I cannot find a way.
I already tried using PJSIP_HEADERS function in a macro invoked on answer (option M of Dial command), but it is returning an empty string for all headers.
Looking at the docs I found that this is the expected behaviour of PJSIP_HEADERS function, so is there a way to read SIP headers from an estabilished outbound call? Specifically I need to get the from-tag and to-tag from the From and To headers.
Using the old chan_sip I could read those data easily using the SIP_HEADERS function.

P.S. I’m using asterisk 13.15

Thanks,
Giulio

I was also looking for this and it seems that it doesn’t work on out channels. The best what I have found for now is to grab it with CHANNEL function: https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Function_CHANNEL

From & Contact -> CHANNEL(pjsip,local_uri)
To -> CHANNEL(pjsip,target_uri) or CHANNEL(pjsip,remote_uri)

I’m using it with Asterisk 15 but as I can see it is provided in version 13 as well.