Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Flavor POST REST API

I've tried to create flavor from Openstack rest API, I already follow the instruction from the documentation, but it returns 200, and it say bad request, is there anything wrong from my json, this is sample of my json image description

and this is the response image description

Flavor POST REST API

I've tried to create flavor from Openstack rest API, I already follow the instruction from the documentation, but it returns 200, and it say bad request, is there anything wrong from my json, this is sample of my json image descriptionjson

private function set_flavorData() { $data = '{ "flavor": { "name": "test_flavor", "ram": 1024, "vcpus": 2, "disk": 10, "id": "10" }

        }';
     return $data;
} 

public function addFlavor(){

    $url = $this->create_uri('/'.$this->tenantId.'/flavors');
    $authData = $this->set_flavorData();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

    curl_setopt($ch, CURLOPT_POST, true);
    #curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $authData);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $this->authToken());

    $response = curl_exec($ch);
    curl_close($ch);

    $result = json_decode($response);
    return $result;
}

and this is the response image descriptionresponse

stdClass Object ( [badRequest] => stdClass Object ( [message] => The server could not comply with the request since it is either malformed or otherwise incorrect. [code] => 400 )

)

Flavor POST REST API

I've tried to create flavor from Openstack rest API, I already follow the instruction from the documentation, but it returns 200, and it say bad request, is there anything wrong from my json, this is sample of my json

private function set_flavorData() {
        $data = '{
                    "flavor": {
                        "name": "test_flavor",
                        "ram": 1024,
                        "vcpus": 2,
                        "disk": 10,
                        "id": "10"
                 }

}

            }';
      return $data;
 } 

 public function addFlavor(){

     $url = $this->create_uri('/'.$this->tenantId.'/flavors');
     $authData = $this->set_flavorData();

     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

     curl_setopt($ch, CURLOPT_POST, true);
     #curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
     curl_setopt($ch, CURLOPT_POSTFIELDS, $authData);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $this->authToken());

     $response = curl_exec($ch);
     curl_close($ch);

     $result = json_decode($response);
     return $result;
 }

and this is the response

stdClass Object ( [badRequest] => stdClass Object ( [message] => The server could not comply with the request since it is either malformed or otherwise incorrect. [code] => 400 )

)

Flavor POST REST API

I've tried to create flavor from Openstack rest API, I already follow the instruction from the documentation, but it returns 200, and it say bad request, is there anything wrong from my json, this is sample of my json

private function set_flavorData() {
        $data = '{
                    "flavor": {
                        "name": "test_flavor",
                        "ram": 1024,
                        "vcpus": 2,
                        "disk": 10,
                        "id": "10"
                 }

            }';
         return $data;
    } 

    public function addFlavor(){

        $url = $this->create_uri('/'.$this->tenantId.'/flavors');
        $authData = $this->set_flavorData();

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

        curl_setopt($ch, CURLOPT_POST, true);
        #curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $authData);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->authToken());

        $response = curl_exec($ch);
        curl_close($ch);

        $result = json_decode($response);
        return $result;
    }

and this is the response

stdClass Object ( [badRequest] => stdClass Object ( [message] => The server could not comply with the request since it is either malformed or otherwise incorrect. [code] => 400 )

)

I try to using curl command on terminal and that works, image description

but why on REST php that doesn't work? can anyone help me?

Flavor POST REST API

I've tried to create flavor from Openstack rest API, I already follow the instruction from the documentation, but it returns 200, and it say bad request, is there anything wrong from my json, this is sample of my json

private function set_flavorData() {
        $data = '{
                    "flavor": {
                        "name": "test_flavor",
                        "ram": 1024,
                        "vcpus": 2,
                        "disk": 10,
                        "id": "10"
                 }

            }';
         return $data;
    } 

    public function addFlavor(){

        $url = $this->create_uri('/'.$this->tenantId.'/flavors');
        $authData = $this->set_flavorData();

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

        curl_setopt($ch, CURLOPT_POST, true);
        #curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $authData);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->authToken());

        $response = curl_exec($ch);
        curl_close($ch);

        $result = json_decode($response);
        return $result;
    }

and this is the response

stdClass Object ( [badRequest] => stdClass Object ( [message] => The server could not comply with the request since it is either malformed or otherwise incorrect. [code] => 400 )

)

I try to using curl command on terminal and that works, image description

but why on REST php that doesn't work? can anyone help me?me???

Flavor POST REST APIAPI : error 400 Bad Request

I've tried to create flavor from Openstack rest API, I already follow the instruction from the documentation, but it returns 200, and it say bad request, is there anything wrong from my json, this is sample of my json

private function set_flavorData() {
        $data = '{
                    "flavor": {
                        "name": "test_flavor",
                        "ram": 1024,
                        "vcpus": 2,
                        "disk": 10,
                        "id": "10"
                 }

            }';
         return $data;
    } 

    public function addFlavor(){

        $url = $this->create_uri('/'.$this->tenantId.'/flavors');
        $authData = $this->set_flavorData();

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

        curl_setopt($ch, CURLOPT_POST, true);
        #curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $authData);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->authToken());

        $response = curl_exec($ch);
        curl_close($ch);

        $result = json_decode($response);
        return $result;
    }

and this is the response

stdClass Object ( [badRequest] => stdClass Object ( [message] => The server could not comply with the request since it is either malformed or otherwise incorrect. [code] => 400 )

)

I try to using curl command on terminal and that works, image description

but why on REST php that doesn't work? can anyone help me???me??? It doesn't work for another POST method in API too,