ARI over outbound websocket - creating an external websocket media channel - 405

Good evening,

I am using the Outbound Websocket for ARI.

It successful connects to my Spring application and some basic RESTRequest over the websocket seems to work find such as listing bridges.

One issue I am having is with creating an external media websocket.

I am following the docs on the ARI over Websocket and I am wanting to get media via a websocket that the asterisk server initiates to my spring application.
I have added the registery WS handler in spring but to be honest asterisk is refusing the request with a 405 before that regardless.

I am using the docs here to form the request over the websocket:

{
“type” : “RESTRequest”,
“transaction_id” : “0_2”,
“request_id” : “0_2”,
“uri” : “/channels/externalMedia”,
“message_body” : “{"app":"my_java_app:PJSIP/6001-00000004","external_host":"ws://localhost:8080/ws/media?callId=0","format":"slin16","transport":"websocket","encapsulation":"none","connection_type":"server","direction":"both","channel":"PJSIP/6001-00000004"}”,
“method” : “POST”,
“content_type” : “application/json”
}

I get the response:

{
“type” : “RESTResponse”,
“transaction_id” : “0_2”,
“request_id” : “0_2”,
“status_code” : 405,
“reason_phrase” : “Method Not Allowed”,
“uri” : “/channels/externalMedia”,
“content_type” : “application/json”,
“message_body” : “{"message":"Invalid method"}”,
“application” : “my_java_app:PJSIP/6001-00000004”,
“timestamp” : “2025-12-05T17:00:31.317+0000”,
“asterisk_id” : “20:2b:20:bf:42:3b”
}

I believe I have formed the request properly and included the required JSON body so I am unsure why I get a 405 (POST does seem to be allowed according to the REST docs).

Thank you for any pointers!

Remove the leading / from the URI. If that doesn’t work, log messages will help…

As before… with the following in cli.conf and DEBUG messages going somewhere.

[startup_commands]
core set debug 4 res_websocket_client.so = pre-module
core set debug 4 ari/ari_websockets.c = pre-module
core set debug 4 ari/ari_websocket_requests.c = pre-module
core set debug 4 res_ari.so = pre-module
core set debug 4 res_http_websocket.so = pre-module


Ah great that did it thank you very much. Will have to remember that one, probably would have expected a 404. Sorry the docs do have a leading / for each path but I assume thats not to be used in the WS api.

It now seems to not like the websocket external_host.

From the docs:

external_host: string - Hostname/ip:port or websocket_client connection ID of external host. May be empty for a websocket server connection.

I assumed this used a asterisk originating websocket connection i.e. “server” that would hit my spring WS endpoint at ws://localhost:8080/ws/media

I have tried with the ws:// protocol prefix and without. Or does it just not like paths and query params on it as the warnging seems to start with the /ws/media….?

I’m specifically talking about the REST uri…

“uri” : “/channels/externalMedia”,

Yes sorry I have done that and now its a 500:
}
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘w’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘s’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘/’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘m’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘e’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘d’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘i’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘a’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘?’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘a’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘l’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘l’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘I’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘d’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘=’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘1’
[Dec 5 18:01:56] WARNING[245533]: app.c:3054 parse_options: Unrecognized option: ‘/’
[Dec 5 18:01:56] ERROR[245533]: chan_websocket.c:1086 websocket_new: no channel: WebSocket client connection ‘localhost:8080’ not found
[Dec 5 18:01:56] ERROR[245533]: chan_websocket.c:1362 webchan_request: no channel: Failed to allocate WebSocket channel pvt
<— Sending ARI event to 127.0.0.1:8080 —>
{
“type”: “RESTResponse”,
“transaction_id”: “1_2”,
“request_id”: “1_2”,
“status_code”: 500,
“reason_phrase”: “Internal Server Error”,
“uri”: “channels/externalMedia”,
“content_type”: “application/json”,
“message_body”: “{“message”:“An internal error prevented this request from being handled”}”,
“application”: “my_java_app:PJSIP/6001-00000007”,
“timestamp”: “2025-12-05T18:01:56.558+0000”,
“asterisk_id”: “20:2b:20:bf:42:3b”
}

I’d suggest reading the documentation for chan_websocket:

You don’t pass in a URL for the external media websocket.

1 Like

external_host must be the outbound websocket connection id for the “websocket” transport.

Ah OK thank you. I assume I will get some specific details in that websocket connection so I can match up the channel or something.

Sorry the docs seem to had suggested I could but maybe I am being confused by the ‘or’.

Yeah that can be confusing because externalMedia can be use with RTP and AudioSocket transports as well. I’ll see if I can re-word it to be clearer.

The page Josh linked above has a section at the bottom that shows an externalMedia example. You can use the ‘transport_data” parameter to pass extra parameters to the channel driver like the v option to add uri parameters.

Scroll up in that page to ‘Using the Dial() Dialplan App ‘ section to see more info about the params you can use.

1 Like

That’s incredibly helpful thank you!

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