how to post an array of object parameter with Guzzle rest client?

时间:2016-04-04 17:21:57

标签: php rest guzzle

i am trying to post this object

{ 
  "product": {
      "id": 80580250,
      "product_code": 1000250,
      "name": "vacuum cleaner",
      "locations": [
        {
          "retailer_id":"12400012",
          "stick": 2000
        },
        {
          "retailer_id":"12400014",
          "stock": 400
        }
      ]
    }
}

i am having a problem with the locations parameter, how do how I write the guzzle client service description so it doesn't translate the parameter into this array of empty objects?

"locations":[
{},
{}
] 

in the request sent to the rest api?

So far based on Guzzle Doc here is what i have been able to come up with, but when logging the request the locations parameter is an array of empty object.

'parameters' => array(
                'id' => array(                      
                    'location' => 'json',
                    'type' => 'integer',
                    'required' => true,
                ),
                'product_code' => array(
                    'location' => 'json',
                    'type' => 'string',
                    'required' => true,
                ),
                'name' => array(
                    'description' => 'vacuum cleaner',
                    'location' => 'json',
                    'type' => 'string',
                    'required' => true,
                ),

                'locations' => array(
                    'location' => 'json',
                    'type' => 'array',
                    'required' => true,
                    "items" => array(
                        "type" => "object",
                        "properties" => array(
                            "retailer_id" => array(
                                "location" => "json",
                                "type" => "integer"
                            ),
                            "stock" => array(
                                "location" => "json",
                                "type" => "integert"
                            )
                        )
                    )
                ),
            ),
        ),

0 个答案:

没有答案