Openstack:400错误请求 - 请求中缺少X-Instance-ID标头

Openstack: 400 Bad Request - X-Instance-ID header is missing from request

When i do http post request to openstack with command:

curl -i -X POST -H "X-Auth-Token: $Token" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"server": {"name": "server", "flavorRef": "1", "imageRef": "Cirros", "security_groups": [{"name": "default" }], "availability_zone": "nova", "networks": "Network1"}}' $OS_AUTH_URL:8775/servers

this message appears to me:

{"message": "X-Instance-ID header is missing from request.<br /><br />\n\n\n", "code": "400 Bad Request", "title": "Bad Request"}

I have read the nova api documentation but i didn't find anything.

The short answer is to change:

$OS_AUTH_URL:8775 to $OS_AUTH_URL:8774/v2/[your_project_id]/servers

Port 8774 should be the default port for the OpenStack Nova service. You can also check the endpoint using curl. So unless you configure the endpoint to port 8775 intentionally, the port number should be 8774

The longer version of the answer would be:

First, you should get the keystone token and you will get your project ID from the result as well.

curl -s -X POST [your_auth_url]/v2.0/tokens \
  -H "Content-Type: application/json" \
  -d '{"auth": {"tenantName": "'"admin"'", "passwordCredentials":
    {"username": "'"admin"'", "password": "'"password"'"}}}' | python -m json.tool

for example, [your_auth_url] = https://127.0.0.1:5000

P.S. This is using the v2.0 keystone auth which is deprecated. For v3, you need to change the v2.0 to v3 and add project_domain_name and user_domain_name along with the username, password. Details here: https://docs.openstack.org/keystone/pike/api_curl_examples.html#v3-api-examples-using-curl

After this, you will get your project_id and token. And you can list images, flavors, keypairs, and etc.

Then, you want to launch an instance:

curl -X POST -H "X-Auth-Token:$1" -H "Content-Type: application/json" -d  '
{       
 "server": {  
   "name": "UsingcUrl",
   "imageRef": "[your_image_id]",
   "flavorRef": "[your_flavor_id]", 
   "key_name" : "[your_keypair_name]"
 }          
}' http://127.0.0.1:8774/v2/[your_project_id]/servers | python -m json.tool

HTH.

I no longer receive that error. But now it ask me a network that i have to insert into body, but the "networks" requires an object.
@Tatta, sorry for the delay. Then you need to create a network first. Do you have the access to the dashboard? Or you can search how to use REST api to create an OpenStack private network with using neutron.

I'm trying to use this command now beacause i saw that "networks" must be an object.

curl -X POST -H "X-Auth-Token:$Token" -H "Content-Type: application/json" -d  '{{"server": {"name": "UsingcUrl","imageRef": "c6839d78-1bc1-4661-9be3-3e9252f0c227","flavorRef": "e07fb38a-1e23-4b92-a1ff-c2fce2d97963","key_name" : "NEWKEY"}}{"networks": {"name": "89c2d870-1cfe-424a-9095-50d60e7b2538"}}}' http://$AUTH_URL:8774/v2/$ID_PROJECT/servers | python -m json.tool

but i receive this message:

{
"badRequest": {
    "code": 400,
    "message": "Malformed request body"
}}
try network rather than networks?