ARI Originate with PJSIP headers

Hello,

We’re looking to replace some app_queue functionality so we’re building an ARI application. One thing that I am struggling to grasp is the creation of custom PJSIP headers.

In our dialplan today we use the b^() parameter for the queue

(queue-xxxx,b(ADD_HEADER^s^1),,,28800,,,,,)
[ADD_HEADER]
exten => s,1,Set(PJSIP_HEADER(add,X-UNIQUEID)=${CHANNEL(LINKEDID)})
 same => n,Set(PJSIP_HEADER(add,X-CALL-ID)=${CHANNEL(pjsip,call-id)})
 same => n,Return()

Now we’re looking to replace this, or add something similar for our ARI Originate. Either we find a way to add the headers and the values, or we somehow pass the channel to a dialplan extension “ADD_HEADER”. But what I have understand is that ARI is not an interface to the dialplan which means we have to rely on building this ourselves.

Much appreciated for any guidance on this. How can we add a similar functionality, or send these headers to the calling extension with the ARI /originate POST?

ARI originate allows using dialplan functions in the variables field, so you would put them there.

You mean the body parameter ‘variables’? Do you have an example of that where an application is used in that param? Is this documented?

I am having troubles understanding how exactly a dialplan application should be set using what is available from the wiki

variables: containers - The “variables” key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { “endpoint”: “SIP/Alice”, “variables”: { “CALLERID(name)”: “Alice” } }

I would imagine something like this.

{
   "variables":{
      "PJSIP_HEADER(add,X-NAME)":"FOOBAR"
   }
}

I don’t have an example contents beyond what is on the documentation site. What you have posted seems correct though. Someone else may chime in with an implementation that they have.

Hmm… I tried, but the SIP headers were not added on the outbound leg towards the extension.

curl -u X:Y-X POST "http://localhost:8088/ari/channels?endpoint=PJSIP%2F1000&extension=1005&timeout=15&app=hello-world" \
-d '{"variables":{"PJSIP_HEADER(add,X-NAME)":"FOOBAR"}}'

Here’s what is returned from the ARI

{
   "type":"Dial",
   "timestamp":"2024-09-30T15:27:53.401+0000",
   "dialstatus":"",
   "forward":"",
   "dialstring":"1000",
   "peer":{
      "id":"1727710073.132",
      "name":"PJSIP/1000-00000058",
      "state":"Down",
      "protocol_id":"32bc2c66-6574-49b5-a1a4-3fcb7fd47b12",
      "caller":{
         "name":"John Doe",
         "number":"1000"
      },
      "connected":{
         "name":"",
         "number":""
      },
      "accountcode":"",
      "dialplan":{
         "context":"organization-8",
         "exten":"s",
         "priority":1,
         "app_name":"AppDial2",
         "app_data":"(Outgoing Line)"
      },
      "creationtime":"2024-09-30T15:27:53.400+0000",
      "language":"en"
   },
   "asterisk_id":"02:91:03:ec:e2:f7",
   "application":"hello-world"
}

{
   "type":"Dial",
   "timestamp":"2024-09-30T15:27:53.446+0000",
   "dialstatus":"RINGING",
   "forward":"",
   "dialstring":"1000",
   "peer":{
      "id":"1727710073.132",
      "name":"PJSIP/1000-00000058",
      "state":"Ringing",
      "protocol_id":"32bc2c66-6574-49b5-a1a4-3fcb7fd47b12",
      "caller":{
         "name":"John Doe",
         "number":"1000"
      },
      "connected":{
         "name":"",
         "number":""
      },
      "accountcode":"",
      "dialplan":{
         "context":"organization-8",
         "exten":"s",
         "priority":1,
         "app_name":"AppDial2",
         "app_data":"(Outgoing Line)"
      },
      "creationtime":"2024-09-30T15:27:53.400+0000",
      "language":"en"
   },
   "asterisk_id":"02:91:03:ec:e2:f7",
   "application":"hello-world"
}

Ah, I fixed it by setting the proper json content-type. Issue is solved then.

For anyone else here’s my full cURL

curl -u X:Y POST "http://localhost:8088/ari/channels?endpoint=PJSIP%2F1000&extension=5002&timeout=15&app=hello-world" -d '{"variables":{"PJSIP_HEADER(add,X-NAME)":"FOOBAR"}}' -H "Content-Type: application/json"