Using the API to execute a command within a live instance

I’m trying to use the API to run the “ls” command from within a live instance. I followed the API documentation and put together the following command:

curl -G -v -H “Authorization: Bearer ${token}” -d id=${instance_id} -d body.command=‘[“ls”]’ -d body.tty.size.height=56 -d body.tty.size.width=56

But when I run it, I get the following error-400:

{“error”:{“code”:3,“message”:“bad_request”,“details”:[{“@type”:“",“locale”:“en-US”,“message”:"first frame is invalid”}]}}

What am I doing wrong?

Hi there!

This endpoint expects you to first open a websocket and then communicate using the struct mentioned in the documentation.

Here is an example:

$ websocat wss:// -H="Sec-WebSocket-Protocol: Bearer, my-bearer-token" # Once you enter this, the websocket is opened and you can input the next line
# ^ This is the response you get 

The API documentation was quite unclear -openAPI does not seem like a good fit for websocket documentation. I’ve added some specifics to the endpoint description in order to make it clearer: Koyeb API reference - Koyeb.

Let me know if you need more details! :slightly_smiling_face:

1 Like

Also, we have a CLI (GitHub - koyeb/koyeb-cli: Koyeb cli), with which you can simply do this:

$ koyeb instances list
132a4486	xxx/fra	HEALTHY	fra   	fra1      	06 Oct 22 16:18 UTC
$ koyeb instances exec 132a4486 ls
next.config.js  node_modules    package.json    public