WooCommerce Order API erstellt immer leere Bestellungen

Lesezeit: 5 Minuten

Marks Benutzeravatar
Markieren

Ich spiele mit der Woo Commerce API (v3.4.4) herum. Ich kann ein Produkt erhalten mit:

curl -X GET \
  'http://localhost/wp-json/wc/v2/products/7?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535381325&oauth_nonce=iApWJblA1A5&oauth_version=1.0&oauth_signature=9T1T43FvOpBzVBU+RQS90zMB/XM=' \
  -H 'Cache-Control: no-cache' \
  -H 'Postman-Token: bdb7f5c9-5719-4bcf-b4fc-38aed3bd5d08'

Ich bekomme die Antwort:

{
    "id": 7,
    "name": "Test product",
    "slug": "test-product",
    "permalink": "http://localhost/product/test-product/",
    "date_created": "2018-08-22T15:25:26",
    "date_created_gmt": "2018-08-22T15:25:26",
    "date_modified": "2018-08-22T15:25:26",
    "date_modified_gmt": "2018-08-22T15:25:26",
    "type": "simple",
    "status": "publish",
    "featured": false,
    "catalog_visibility": "visible",
    "description": "<p>this is a test product</p>\n",
    "short_description": "<p>the short desc</p>\n",
    "sku": "",
    "price": "9",
    "regular_price": "10",
    "sale_price": "9",
    "date_on_sale_from": null,
    "date_on_sale_from_gmt": null,
    "date_on_sale_to": null,
    "date_on_sale_to_gmt": null,
    "price_html": "<del><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&euro;</span>10.00</span></del> <ins><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&euro;</span>9.00</span></ins>",
    "on_sale": true,
    "purchasable": true,
    "total_sales": 3,
    "virtual": false,
    "downloadable": false,
    "downloads": [],
    "download_limit": -1,
    "download_expiry": -1,
    "external_url": "",
    "button_text": "",
    "tax_status": "taxable",
    "tax_class": "",
    "manage_stock": false,
    "stock_quantity": null,
    "in_stock": true,
    "backorders": "no",
    "backorders_allowed": false,
    "backordered": false,
    "sold_individually": false,
    "weight": "",
    "dimensions": {
        "length": "",
        "width": "",
        "height": ""
    },
    "shipping_required": true,
    "shipping_taxable": true,
    "shipping_class": "",
    "shipping_class_id": 0,
    "reviews_allowed": true,
    "average_rating": "0.00",
    "rating_count": 0,
    "related_ids": [
        36,
        41
    ],
    "upsell_ids": [],
    "cross_sell_ids": [],
    "parent_id": 0,
    "purchase_note": "",
    "categories": [
        {
            "id": 15,
            "name": "Uncategorized",
            "slug": "uncategorized"
        }
    ],
    "tags": [],
    "images": [
        {
            "id": 8,
            "date_created": "2018-08-22T15:24:00",
            "date_created_gmt": "2018-08-22T15:24:00",
            "date_modified": "2018-08-22T15:24:00",
            "date_modified_gmt": "2018-08-22T15:24:00",
            "src": "http://localhost/wp-content/uploads/2018/08/sock.jpeg",
            "name": "sock",
            "alt": "",
            "position": 0
        }
    ],
    "attributes": [
        {
            "id": 0,
            "name": "size",
            "position": 0,
            "visible": true,
            "variation": false,
            "options": [
                "small",
                "medium",
                "large"
            ]
        }
    ],
    "default_attributes": [],
    "variations": [],
    "grouped_products": [],
    "menu_order": 0,
    "meta_data": [],
    "_links": {
        "self": [
            {
                "href": "http://localhost/wp-json/wc/v2/products/7"
            }
        ],
        "collection": [
            {
                "href": "http://localhost/wp-json/wc/v2/products"
            }
        ]
    }
}

Dies funktioniert, indem die Anforderung mit CURL in der Befehlszeile ausgeführt wird und die Anforderung in Postman ausgeführt wird.

Aber jetzt versuche ich, eine Bestellung zu erstellen:

curl -X POST \
  'http://localhost/wp-json/wc/v2/orders?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535382336&oauth_nonce=P8RWaD9DnZ9&oauth_version=1.0&oauth_signature=GFxtI7+gqbah5fu68gSdqL4V3fs=" \
  -H "Cache-Control: no-cache' \
  -H 'Postman-Token: f17bec6a-c76b-4a6c-8797-1df9dac73f36' \
  -d '{
  "payment_method": "bacs",
  "payment_method_title": "Direct Bank Transfer",
  "set_paid": true,
  "billing": {
    "first_name": "John",
    "last_name": "Doe",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
    "email": "[email protected]",
    "phone": "(555) 555-5555"
  },
  "shipping": {
    "first_name": "John",
    "last_name": "Doe",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US"
  },
  "line_items": [
    {
      "product_id": 7,
      "quantity": 1
    }
  ],
  "shipping_lines": [
    {
      "method_id": "flat_rate",
      "method_title": "Flat Rate",
      "total": 7
    }
  ]
}'

Wenn ich die obige Anfrage mit Postman ausführe, wird eine leere Bestellung erstellt und ich erhalte die Antwort:

{
    "id": 59,
    "parent_id": 0,
    "number": "59",
    "order_key": "wc_order_5b8413f8ed585",
    "created_via": "rest-api",
    "version": "3.4.4",
    "status": "pending",
    "currency": "EUR",
    "date_created": "2018-08-27T15:08:40",
    "date_created_gmt": "2018-08-27T15:08:40",
    "date_modified": "2018-08-27T15:08:41",
    "date_modified_gmt": "2018-08-27T15:08:41",
    "discount_total": "0.00",
    "discount_tax": "0.00",
    "shipping_total": "0.00",
    "shipping_tax": "0.00",
    "cart_tax": "0.00",
    "total": "0.00",
    "total_tax": "0.00",
    "prices_include_tax": false,
    "customer_id": 0,
    "customer_ip_address": "",
    "customer_user_agent": "",
    "customer_note": "",
    "billing": {
        "first_name": "",
        "last_name": "",
        "company": "",
        "address_1": "",
        "address_2": "",
        "city": "",
        "state": "",
        "postcode": "",
        "country": "",
        "email": "",
        "phone": ""
    },
    "shipping": {
        "first_name": "",
        "last_name": "",
        "company": "",
        "address_1": "",
        "address_2": "",
        "city": "",
        "state": "",
        "postcode": "",
        "country": ""
    },
    "payment_method": "",
    "payment_method_title": "",
    "transaction_id": "",
    "date_paid": null,
    "date_paid_gmt": null,
    "date_completed": null,
    "date_completed_gmt": null,
    "cart_hash": "",
    "meta_data": [],
    "line_items": [],
    "tax_lines": [],
    "shipping_lines": [],
    "fee_lines": [],
    "coupon_lines": [],
    "refunds": [],
    "_links": {
        "self": [
            {
                "href": "http://localhost/wp-json/wc/v2/orders/59"
            }
        ],
        "collection": [
            {
                "href": "http://localhost/wp-json/wc/v2/orders"
            }
        ]
    }
}

Bizarrerweise erhalte ich die Antwort, wenn ich GENAU dieselbe Anfrage mit CURL in der Befehlszeile ausführe:

{"code":"woocommerce_rest_authentication_error","message":"Invalid signature - provided signature does not match.","data":{"status":401}}

Wenn ich die Anfrage in Postman laufen lasse, aber für "product_id" ich benutze "this is a completely fake id" Es erstellt immer noch eine leere Bestellung und antwortet mit:

{
    "id": 60,
    "parent_id": 0,
    "number": "60",
    "order_key": "wc_order_5b84148e002da",
    "created_via": "rest-api",
    "version": "3.4.4",
    "status": "pending",
    "currency": "EUR",
    "date_created": "2018-08-27T15:11:10",
    "date_created_gmt": "2018-08-27T15:11:10",
    "date_modified": "2018-08-27T15:11:10",
    "date_modified_gmt": "2018-08-27T15:11:10",
    "discount_total": "0.00",
    "discount_tax": "0.00",
    "shipping_total": "0.00",
    "shipping_tax": "0.00",
    "cart_tax": "0.00",
    "total": "0.00",
    "total_tax": "0.00",
    "prices_include_tax": false,
    "customer_id": 0,
    "customer_ip_address": "",
    "customer_user_agent": "",
    "customer_note": "",
    "billing": {
        "first_name": "",
        "last_name": "",
        "company": "",
        "address_1": "",
        "address_2": "",
        "city": "",
        "state": "",
        "postcode": "",
        "country": "",
        "email": "",
        "phone": ""
    },
    "shipping": {
        "first_name": "",
        "last_name": "",
        "company": "",
        "address_1": "",
        "address_2": "",
        "city": "",
        "state": "",
        "postcode": "",
        "country": ""
    },
    "payment_method": "",
    "payment_method_title": "",
    "transaction_id": "",
    "date_paid": null,
    "date_paid_gmt": null,
    "date_completed": null,
    "date_completed_gmt": null,
    "cart_hash": "",
    "meta_data": [],
    "line_items": [],
    "tax_lines": [],
    "shipping_lines": [],
    "fee_lines": [],
    "coupon_lines": [],
    "refunds": [],
    "_links": {
        "self": [
            {
                "href": "http://localhost/wp-json/wc/v2/orders/60"
            }
        ],
        "collection": [
            {
                "href": "http://localhost/wp-json/wc/v2/orders"
            }
        ]
    }
}

Also ich habe mehrere Probleme:

1/ Egal welche product_id ich verwende, die erstellte Bestellung ist immer leer

2/ Selbst wenn ich eine gefälschte product_id angebe, wird dennoch eine Bestellung von Woo Commerce erstellt. Das ist doch sicher falsch?

3/ Das Ausführen der Anforderungen zum Erstellen von Bestellungen auf der Befehlszeile gibt Postman unterschiedliche Antworten

  • Können Sie einen Screenshot Ihres Postbotenfensters bereitstellen?

    – Jack Robson

    30. August 2018 um 18:27 Uhr

  • Können Sie versuchen, die SKU-Nummer von WooCommerce zu verwenden, um das Produkt zuzuordnen? So kann es alle anderen Informationen darüber abrufen. Und das Teilen von Screenshots wird sicherlich helfen. Vielen Dank

    – Robin

    30. August 2018 um 21:49 Uhr

  • Können Sie nur bestätigen, ob Sie haben Flat Rate Versandart?

    – WordPress auslagern

    2. September 2018 um 7:40 Uhr

Ich habe gefehlt:

-H 'Content-Type: application/json' \

aus der Anfrage. Ich hatte dies in Postman eingegeben, aber das Kontrollkästchen nicht aktiviert:

Geben Sie hier die Bildbeschreibung ein

1386890cookie-checkWooCommerce Order API erstellt immer leere Bestellungen

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy