Magento 2 API (Updated 2024): Create an order

Table of Contents

In this post, I will show you how to create an order using an offline payment method. Therefore, this endpoint below only requires the payment method and billing address information. Follow our example code to find out how to create your own order by Magento 2 API.

Step 1: Generate Access Token

First, to create a customer account, admin authorization is required. Complete the following steps to authorize access to resources:

In the POST request enter your store URL along with this endpoint.

POST <host>/rest/V1/integration/customer/token

Enter your customer username and password in Body sections, then click Send

{
  "username": "string",
  "password": "string"
}

Step 2: Create an order

When you request payment details, Magento makes an order and sends a confirmation of the order to the customer.

Create a new request with this endpoint:

POST <host>/rest/V1/carts/mine/payment-information

In the Authorization section:

  • Choose Type: Bearer Token
  • Then paste your token

In Payload section:

{
  "paymentMethod": {
    "method": "checkmo"
  },
  "billing_address": {
    "email": "julielawson@example.com",
    "region": "Nevada",
    "region_id": 39,
    "region_code": "NV",
    "country_id": "US",
    "street": ["3703 Wescam Court"],
    "postcode": "89406",
    "city": "Fallon",
    "telephone": "860-212-5597",
    "firstname": "Julie",
    "lastname": "Lawson"
  }
}

Response

An order ID

Create order code magento 2 api

When you review the order as Admin, the response contains full details about the order, such as customer information, payment details for the order and each individual item.

Step 3: Verify the order

  1. Log in to the store with the example account and check your order.
  2. Log in to your Magento Admin. Then go to Sales > Orders. Use the order Id to search for your pending order.
Verify order as admin

Above, I have just provided you with three steps on how to convert the quote to an order. I hope it would be helpful for you when creating an order using Magento API. For more information, you can refer to Magento DevDocs. If you have any questions or new ideas, feel free to leave a comment below.