Creating new instance over REST API

When creating a new instance over REST API there is no information if it was successful or not, or any results for this action. How can I verify it? Do I have to just query for an instance if it exists?

curl -X "POST" "https://incus.xyz.com/1.0/instances" \
     -H 'Authorization: Bearer XYZ' \
     -d $'{
  "source": {
    "alias": "hello-world",
    "protocol": "oci",
    "type": "image",
    "server": "https://docker.io"
  }
}'

Even when I send a wrong “body” I always get the same response. Eg. omitting “protocol” from it will not create an instance (understandably)

{
  "type": "async",
  "status": "Operation created",
  "status_code": 100,
  "operation": "/1.0/operations/ea6ac694-e325-442d-9cc2-ff55c64078a9",
  "error_code": 0,
  "error": "",
  "metadata": {
    "id": "ea6ac694-e325-442d-9cc2-ff55c64078a9",
    "class": "task",
    "description": "Creating instance",
    "created_at": "2025-01-29T16:03:54.867205334Z",
    "updated_at": "2025-01-29T16:03:54.867205334Z",
    "status": "Running",
    "status_code": 103,
    "resources": {
      "instances": [
        "/1.0/instances/pro-jaguar"
      ]
    },
    "metadata": null,
    "may_cancel": false,
    "err": "",
    "location": "none"
  }
}

I know there is an “operation” but it gets away. Are processed operations queryable?

You have 5 seconds between an operation reaching a final state and it going away.

You could probably also use incus monitor to see what’s going on in Incus and tweak your request accordingly.

Lastly you can also use incus query as a way to send a raw API query, that supports background operations (with --wait) and so will get you the operation error in this case.

Thank you @stgraber

Can I increase “5 seconds” for an operation going away?

Yeah, I use incus monitor to debug.

Can I use /1.0/operations/{id}/wait as a follow up request to get that status? I would like to get a state directly from REST API.

What is the “token” mentioned in /1.0/operations/{id}/wait?public?

Yeah GET /1.0/operations/UUID/wait should work fine, just got to hit it as soon as you get given the background operation UUID

1 Like

I would also consider the phone_home module in cloud-init in case your setup is more complicated or has many stages, if your goal is to know when everything is good

https://cloudinit.readthedocs.io/en/latest/reference/modules.html#phone-home

1 Like

That’s a great tip @evadne , thank you!