Multiple variables on post to ari/channels

Hi!

I’m trying to originate a call through ARI using python requests module. I get the call but I cannot see on the dialplan any of the vars I set in the request.
I can see in the docs this but I don’t know what I’m doing wrong:

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” } }

Here is the code I’m using to test this:

import requests

USER = "asterisk"
PASS = "asterisk"
IP = "127.0.0.1"
PORT = "8088"

number = "123456789"

url = (
    f"http://{IP}:{PORT}/ari/channels?"
    f"endpoint=PJSIP/{number}@trunk&"
    "context=outgoing&"
    "extension=666&"
    "priority=1&"
    "callerId=bot&"
    "timeout=20"
)

body = {
    "variables": {
        "call_id": "1234",
        "number": number,
        "question": "1a",
        "bot": "54321"
    }
}

resp = requests.post(
        url,
        auth=(USER, PASS),
        data=body)

print(resp.text)

In the dialplan I’m trying to get the variables like this:

NoOp(IDENTIFICADOR =====> ${call_id})

Thank you in advance.

Nevermind… I was sending body as a string instead of json. Changing data parameter to json it works perfect:

resp = requests.post(
        url,
        auth=(USER, PASS),
        json=body)

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