0

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": "[email protected]",
    "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?

1 Answer 1

3

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": "[email protected]",
    "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": "[email protected]"
}

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'.

4
  • 1
    Thank you thank you thank you... That's sorted it out
    – freestate
    Commented Mar 29, 2021 at 10:45
  • You are most welcome!
    – Diana
    Commented Mar 29, 2021 at 11:12
  • @DianaBotean could I use your answer to submit a PR for devdocs?
    – Jimmy
    Commented Mar 30, 2021 at 7:02
  • 1
    sure, feel free to do so :)
    – Diana
    Commented Mar 30, 2021 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.