Magento 2 API Create Order As guest: {“message”:“\”%fieldName\“ is required. Enter and try again.”,“parameters”:{“fieldName”:“email”}}

magento.stackexchange https://magento.stackexchange.com/questions/334702

Domanda

0

I'm trying to place an order via Magento 2 API as a guest, following the guidance shown here:

https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-create-order.html

The end point I'm using is:

https://[domain]/rest/V1/guest-carts/'.$quote_id.'/payment-information

with quote_id being the ID of the quote created initially

Steps 1-6 complete successfully with relevant response being returned as expected.

But sending the following payload (literally a copy and paste from the docs) to the above endpoint:

    {
  "paymentMethod": {
    "method": "banktransfer"
  },
  "billing_address": {
    "email": "jdoe@example.com",
    "region": "New York",
    "region_id": 43,
    "region_code": "NY",
    "country_id": "US",
    "street": [
      "123 Oak Ave"
    ],
    "postcode": "10577",
    "city": "Purchase",
    "telephone": "512-555-1111",
    "firstname": "Jane",
    "lastname": "Doe"
  }
}

Results in this error message:

{"message":""%fieldName" is required. Enter and try again.","parameters":{"fieldName":"email"}}

The email address IS obviously being supplied, and am really at a loss as to what's going wrong.

For info, the API this is being sent to is a vanilla install of Magento set up with a test product for testing purposes

Does anyone have any ideas, or at least some suggestions as to how I can debug given the not very usefulness of the error message given?

È stato utile?

Soluzione

By checking the Redoc reference of this endpoint, you will see that the email field is required also outside the billing address array - https://magento.redoc.ly/2.4.2-guest/#operation/checkoutGuestPaymentInformationManagementV1SavePaymentInformationAndPlaceOrderPost.

Basically your payload should look something like this:

{
  "paymentMethod": {
    "method": "banktransfer"
  },
  "billingAddress": {
    "email": "jdoe@example.com",
    "region": "New York",
    "region_id": 43,
    "region_code": "NY",
    "country_id": "US",
    "street": [
      "123 Oak Ave"
    ],
    "postcode": "10577",
    "city": "Purchase",
    "telephone": "512-555-1111",
    "firstname": "Jane",
    "lastname": "Doe"
  },
  "email": "jdoe@example.com"
}

It looks like the documentation is incomplete, since it doesn't mention the required 'email' field and also please note that there is a typo in the documentation: 'billing_address' key should be 'billingAddress'.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top