1

私は ApiGility を初めて使用し、ルートに追加された API 呼び出しを介してショッピング カートを更新しようとしています。コード接続APIでZend Framework 2を使用しています。

私が現在直面している問題は、何を試しても、検証エラーなしで情報を API に入れることができないことです。

私のmodule.config:

カート設定の更新:

 'Api\\V1\\Rest\\Updatecart\\Controller' => array(
        'listener' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartResource',
        'route_name' => 'api.rest.updatecart',
        'route_identifier_name' => 'updatecart_id',
        'collection_name' => 'updatecart',
        'entity_http_methods' => array(
            0 => 'GET',
            1 => 'PATCH',
            2 => 'PUT',
            3 => 'DELETE',
        ),
        'collection_http_methods' => array(
            0 => 'GET',
            1 => 'POST',
            2 => 'PUT',
            3 => 'PATCH',
            4 => 'DELETE',
        ),
        'collection_query_whitelist' => array(
            0 => 'prod_id',
            1 => 'quantity',
            2 => 'quantity_accumulation',
            3 => 'tax',
        ),
        'page_size' => 25,
        'page_size_param' => null,
        'entity_class' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartEntity',
        'collection_class' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartCollection',
        'service_name' => 'updatecart',
    ),

関連するフィルター設定:

'Api\\V1\\Rest\\Updatecart\\Validator' => array(
        0 => array(
            'name' => 'prod_id',
            'required' => true,
            'filters' => array(
                0 => array(
                    'name' => 'Zend\\Filter\\Int',
                    'options' => array(),
                ),
            ),
            'validators' => array(),
            'description' => 'The id of the product in the cart to be updated',
            'error_message' => 'Missing product id',
            'allow_empty' => false,
            'continue_if_empty' => false,
        ),
        1 => array(
            'name' => 'quantity',
            'required' => true,
            'filters' => array(),
            'validators' => array(),
            'description' => 'quantity of product',
            'error_message' => 'You must include a quantity',
            'allow_empty' => false,
            'continue_if_empty' => false,
        ),
        2 => array(
            'name' => 'tax',
            'required' => true,
            'filters' => array(),
            'validators' => array(),
            'description' => 'Add the VAT, GST, Sales Tax that will be applicable to this item. Use 0.00 for no value.',
            'error_message' => 'Please add a tax value, 0.00 for no value.',
            'allow_empty' => false,
            'continue_if_empty' => false,
        ),
        3 => array(
            'name' => 'quantity_accumulation',
            'required' => true,
            'filters' => array(
                0 => array(
                    'name' => 'Zend\\Filter\\Boolean',
                    'options' => array(),
                ),
            ),
            'validators' => array(),
            'description' => 'Either accumulate the entered quantity to the current basket quantity or set as the entered quantity.',
            'allow_empty' => false,
            'continue_if_empty' => false,
            'error_message' => 'Quantity accumulation field error.',
        ),
    ),

PUT メソッドを呼び出す場合:

https://cloud.mysite.dev:8890/api/updatecart/1?prod_id=1&quantity=1&update_type=1&tax=0.00

Failed Validation エラーが発生し続けます。

{
"validation_messages": {
"prod_id": [
"Missing product id"
],
"quantity": [
"You must include a quantity"
],
"tax": [
"Please add a tax value, 0.00 for no value."
],
"quantity_accumulation": [
"Quantity accumulation field error."
]
},
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Unprocessable Entity",
"status": 422,
"detail": "Failed Validation"
}
4

1 に答える 1

1

json 形式の http 本文 (ペイロード) としてデータを提供する必要があります。クエリ パラメータを指定せずに URI を呼び出します。

https://cloud.mysite.dev:8890/api/updatecart/1

{
    "prod_id": 1,
    "quantity": 1,
    "update_type": 1,
    "tax": "0.00"
}

また、正しいリクエスト ヘッダーを指定していることを確認してください。

Accept: application/json
Content-Type: application/json
于 2015-01-15T14:17:50.787 に答える