How can I set parameter in Guzzle service description to be a json array? This is what I have tried but is not working:
$service_description = new Description([ 'baseUri' => 'http://api.etrackerplus.com/api', 'operations' => [ 'createOrder' => [ 'httpMethod' => 'POST', 'uri' => 'api/stores/{store_id}/orders/new.json', 'responseModel' => 'getResponse', 'parameters' => [ 'store_id' => [ 'type' => 'string', 'location' => 'uri' ], "order" => [// <== HERE!!! "location" => "json", "type" => "array" ] ] ] ], 'models' => [ 'getResponse' => [ 'type' => 'object', 'additionalProperties' => [ 'location' => 'json' ] ] ] ]);
Call:
$response = $client->createOrder(['store_id' => '23',array( 'order'=> array("order_number" => "1233"))]);
The json correct json structure to be send is this:
{ "order": { "order_number": "97221" } }
Advertisement
Answer
You have to write nested
definitions as per JSON schema validation rules.
I had done this with XML based requests. Let me try this in JSON based data. Hope this helps:
"order" => [ "location" => "json", "type" => "object", // Because it's associative array in PHP but object in JS. Use "array" only if it's indexed array "properties" => [ // define nested property order_number (by default type is string "order_number" => [ "location" => "json", ], ], ],