Force delete running container

Container is running.
CLI:
lxc delete --force

What are the steps in rest api equivalent to above?

I have tried:
1)
/1.0/instances/name/state
PUT
{ “action”: “stop”, “force”: true, “stateful”: false }
status_code: 100 , operation created, Stopping instance
2)
/1.0/instances/name
DELETE
status_code: 400, Instance is running

This happens in instances with very limited resources, seems the stop action (though forceful) doesnt finish fast enough.

PUT /1.0/instances/c1/state
	{
		"action": "stop",
		"timeout": -1,
		"force": true,
		"stateful": false
	} 

I think you will need to watch for the operation to complete.

“timeout”: -1, hasnt help.
Problem is, I start a newly created instance. It has very limited resources(CPU RAM …)
Than I force stop and delete it.
It seems the process of stopping takes too long despite:
{
“action”: “stop”,
“timeout”: -1,
“force”: true,
“stateful”: false
}
so, an immediate delete doesnt work.

I wished, at least this one would go easy without monitoring processes.
But indeed, operation need to be watched.
BTW, is there a clear instruction or examples of those two operations polling modes?
/1.0/operations/uuid/wait
/1.0/operations/uuid/websocket

You can just hit /wait for a blocking call until the operation is complete.
/websocket is only used for websocket operations (migrate, exec, console, …).

The other way to monitor operations is to connect to /1.0/events ahead of time (also a websocket) and then monitor the notification messages received on it. That’s what the CLI does as that’s a bit lighter weight and in some cases less racy than hitting /wait, but it’s quite a bit harder to implement so for what you want, just use /wait.

Running in shell, I dont see any difference in a 1 second loop polling of:
/1.0/operations/uuid/wait
and
/1.0/operations/uuid

both do the same and at some point operation disappears as expected.

My question is, what is the purpose of “/wait”?

/wait is blocking and will not return the operation data until the operation reaches a final state.