Using the API to execute a command within a live instance

Hi.
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}” https://app.koyeb.com/v1/streams/instances/exec -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”:“type.googleapis.com/google.rpc.LocalizedMessage",“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://app.koyeb.com/v1/streams/instances/exec -H="Sec-WebSocket-Protocol: Bearer, my-bearer-token" # Once you enter this, the websocket is opened and you can input the next line
{"id":"my-instance-id","body":{"command":["/bin/ls"]}}
{"data":"G1swOzBtbmV4dC5jb25maWcuanMbW20gIBtbMTszNG1ub2RlX21vZHVsZXMbW20gICAgG1swOzBtcGFja2FnZS5qc29uG1ttICAgIBtbMTszNG1wdWJsaWMbW20NCg=="},"stderr":null,"exited":false,"exit_code":0}}
# ^ 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
ID      	SERVICE              	STATUS 	REGION	DATACENTER	CREATED AT
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
2 Likes