【问题标题】:WooCommerce returning errorWooCommerce 返回错误
【发布时间】:2017-01-13 06:58:37
【问题描述】:

尝试通过 cURL 创建虚拟订单时出现此错误。我试图通过邮局局长创建订单。我只是从 woocommerrce documentation 复制代码,但仍然出现错误 代码是

    curl -X POST -H "Content-Type: application/javascript" -H "Cache-Control: no-cache" -H "Postman-Token: 56032927-8d69-3630-aae9-0eb6823fe9b0" -d '{
      "payment_method": "cod",
      "payment_method_title": "Cash on Delivery",
      "set_paid": true,
      "billing": {
        "first_name": "bhbhub",
        "last_name": "Dnuoe",
        "address_1": "969 Market",
        "address_2": "",
        "city": "beach",
        "state": "Goa",
        "postcode": "122002",
        "country": "India",
        "email": "john.doe@example.com",
        "phone": "1234567890"
      },
      "shipping": {
        "first_name": "John",
        "last_name": "Doe",
        "address_1": "969 Market",
        "address_2": "",
        "city": "beach",
        "state": "Goa",
        "postcode": "94103",
        "country": "US"
      },
      "line_items": [
        {
          "product_id": 100,
          "quantity": 2
        }

      ],
      "shipping_lines": [
        {
          "method_id": "flat_rate",
          "method_title": "Flat Rate"


        }
      ]
    }' "http://www.jersershor.com/wc-api/v3/orders?oauth_consumer_key=ck_638caaf46271a320075ecee01e89581f91644b98&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1484290102&oauth_nonce=cwidKMBu2uE&oauth_version=1.0&oauth_signature=VUMuuVRXsXKvyFhk97dQWj5bCEI%3D
"

【问题讨论】:

标签: json wordpress api post woocommerce


【解决方案1】:

问题在于 woocommerce 的文档

需要将您的请求正文 JSON 包装在 order 对象中才能开始。所以它就像 { "order": { ...上面的数据 } }

所以正文的代码将是

{ “订单”:{

"status": "processing",

    "payment_details": {
        "method_id": "bacs",
        "method_title": "Direct Bank Transfer",
        "paid": true

    },

    "billing_address": {
        "first_name": "bhbhub",
        "last_name": "Dnuoe",
        "address_1": "969 Market",
        "address_2": "",
        "city": "beach",
        "state": "Goa",
        "postcode": "122002",
        "country": "IN",
        "email": "john.doe@example.com",
        "phone": "1234567890"
    },
    "shipping_address": {
        "first_name": "John",
        "last_name": "Doe",
        "address_1": "969 Market",
        "address_2": "",
        "city": "beach",
        "state": "Goa",
        "postcode": "94103",
        "country": "IN"
    },
    "line_items": [{
            "product_id": 100,
            "quantity": 2
        }

    ],
    "customer": {
        "id": 0,
        "total_spent": "320",
        "email": "john.doe@example.com",
        "first_name": "bhbhub",
        "last_name": "Dnuoe",
        "billing_address": {
            "first_name": "bhbhub",
            "last_name": "Dnuoe",
            "company": "",
            "address_1": "969 Market",
            "address_2": "",
            "city": "beach",
            "state": "Goa",
            "postcode": "122002",
            "country": "IN",
            "email": "john.doe@example.com",
            "phone": "1234567890"
        },
        "shipping_address": {
            "first_name": "John",
            "last_name": "Doe",
            "company": "",
            "address_1": "969 Market",
            "address_2": "",
            "city": "beach",
            "state": "Goa",
            "postcode": "94103",
            "country": "IN"
        }
    }
}

}

【讨论】:

    猜你喜欢
    • 2015-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    相关资源
    最近更新 更多