Customer Account REST APIs With Example in Magento 2

For any new customer of the Magento 2 eCommerce website from creating an account to deleting the account, the details of any customer account rest apis required are being given in this post.

In this Customer API List, I am telling you in detail about each API.

I'll run each endpoint on Postman to show you an example of how each of the customer's APIs works.

Customer Account REST APIs
Customer APIs

 

List of Magento 2 Customer Account REST APIs

By the way, there are only a few customer rest APIs in Magento 2 which we frequently use.

It also depends on the function of our mobile application and what kind of functionality we want to provide to our customers.

Based on that, I am giving you the details of the Most Frequently Used Rest API, which has been prepared as an index in a way.

With this list of Magento 2's Customer Rest APIs, it will be easier for you to develop mobile applications.

 

1. Get Customer Details By Customer ID

This rest api will help you to get the customer account information by the getById service method.

Endpoint:

<host>/rest/<store_code>/V1/customers/:customerId

Method: GET

Headers:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

2. Create Customer Account REST APIs

You need to use this REST API to create a new customer account. This is the REST API for Magento 2's default customer account creation.

Endpoint:

<host>/rest/<store_code>/V1/customers

Method: POST

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

Create customer api detail with parameter

 

3. Save Customer Information API

When data is to be saved based on customer id then we save data by sending payload in Magento 2 customer rest api.

Endpoint:

<host>/rest/<store_code>/V1/customers/:customerId

Method: PUT

Header:

  • Authorization: Bearer <customer_token>
  • Content-Type: application/json

 

4. Customer API to Save Data

If Magento 2 customer data has to be saved without customer id then we use this rest api.

And also send the customer token in the header as authorization.

Endpoint:

<host>/rest/<store_code>/V1/customers/me

Method: PUT

Header:

  • Authorization: Bearer <customer_token>
  • Content-Type: application/json

 

5. Get Customer Information REST API

In Magento 2 store we use this api when we have to get customers' data.

In this, only we have to send the customer's token by putting it in the header and then we get all the details of the customer.

We have to gate all the details of the customer with only the login details of the customer, even then on the basis of this get by ID, we gate the information through this API.

Endpoint:

<host>/rest/<store_code>/V1/customers/me

Method: GET

Header:

  • Authorization: Bearer <admin_token>
  • Content-Type: application/json

 

6. Activate Customer ID via REST API

We use this api in Magento 2 to activate the customer id by activateById.

Endpoint:

<host>/rest/<store_code>/V1/customers/me/activate

Method: PUT

Header:

  • Authorization: Bearer <admin_token>
  • Content-Type: application/json

 

7. Search Customer REST API

This api help to get the list of the customer by the getList service method.

Endpoint:

<host>/rest/<store_code>/V1/customers/search

Method: GET

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

8. Activate Customer Email API

To activate the email id of the customer of magento 2, we use this rest api.

Endpoint:

<host>/rest/<store_code>/V1/customers/:email/activate

Method: GET

Header:

  • Authorization: Bearer <admin_token>
  • Content-Type: application/json

 

9. Change Customer Password REST API

Magento 2 Store by default provides REST API to change the password of the customer, using changePasswordById one can change the password of any customer account.

Endpoint:

<host>/rest/<store_code>/V1/customers/me/password

Method: PUT

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

10. Send Customer Password Lest Link API

Using the customer's token to send the reset password link to the customer's mail id, we use the validateResetPasswordLinkToken API.

Endpoint:

<host>/rest/<store_code>/V1/customers/:customerId/password/resetLinkToken/:resetPasswordLinkToken

Method: GET

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

11. Initiate Customer REST Password API

If the API is to be used to initiate the password reset, then we can change the password of any customer using this initiatePasswordReset API.

Endpoint:

<host>/rest/<store_code>/V1/customers/password

Method: PUT

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

12. Reset Password API

In this API, you have to enter the old password of the customer along with the new password that you want to select and hit it with the admin token.

Endpoint:

<host>/rest/<store_code>/V1/customers/resetPassword

Method: POST

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

13. Confirm Customer Account API

When a customer creates an account on the Magento store then we can choose the account confirmation or rejections option from the admin.

And after selecting the same option, you can use the API to get the confirmation status of the customer via rest api in Magento 2.

Endpoint:

<host>/rest/<store_code>/V1/customers/:customerId/confirm

Method: GET

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

14. Customer Account Confirmation API

And after selecting the customer account confirmation option, you can use this API to resend confirmation and validate the account status of any customer through the rest of the API.

Endpoint:

<host>/rest/<store_code>/V1/customers/confirm

Method: POST

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

15. Validate Customer Account API

This api provides a facility to validate any customer account by this any customer account can be validated through the rest api.

Endpoint:

<host>/rest/<store_code>/V1/customers/validate

Method: PUT

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

16. Read-Only Customer Account API

You can get the customer detail like isReadonly or not.

Endpoint:

<host>/rest/<store_code>/V1/customers/:customerId/permissions/readonly

Method: GET

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

17. Delete Customer By ID REST API

Magento2 also provides the facility of default rest api to delete customer accounts based on id. Using this, you can delete any customer on the basis of a customer ID.

Endpoint:

<host>/rest/<store_code>/V1/customers/:customerId

Method: DELETE

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

18. Check Email Available or not Via REST API

When creating a customer account, we have to check the email id.

Now if you want to check customer email id whether it is available or not then you can use this isEmailAvailable REST API for that.

Endpoint:

<host>/rest/<store_code>/V1/customers/isEmailAvailable

Method: POST

Header:

  • Authorization: Bearer <token>
  • Content-Type: application/json

 

 

References:

https://magento.stackexchange.com/

https://devdocs.magento.com/

Magento 2 All REST API List for Mobile App Development

There is no documentation in Magento where you can see the complete Magento 2 All REST APIs of catalog, customer, and checkout at one place.

If you look at the documentation on the official website of Magento, you will find that you can get the list of all APIs using Document Swagger.

But this documentation keeps so many details together that we find it a bit complicated and sometimes we are not able to extract the important things.

I am solving your problem through this documentation where you will get the list of default api of Magento with body details.

In this, you will see as much detail as you need and I have removed the things which are not needed.

All the components that are there by default like Catalog APIs, Customer APIs, Checkout APIs, CMS APIs, Payment APIs, Reviews APIs, Shipping APIs, Wishlist APIs, etc. I am giving all the list here.

Magento 2 All REST APIs List

 

Magento 2 All REST APIs List for Catalog

All the necessary APIs for the catalog will be available to you through this.

For this, what endpoint do you need and the payload that we send in the body so that we can save the data?

  1. Product Service APIs
  2. Tier Price APIs
  3. Product Custom Options APIs
  4. Product Links APIs
  5. Category Product Links APIs
  6. Product Website Links APIs

 

Read more: Best 3 Simple Ways to Upgrade Magento 2 Store in 2022

 

Customer APIs List

In this list, we have prepared the details of all the endpoints of the customer API, such as how to get the metadata of a customer, you will get the details of all the APIs of the customer group.

To get data of customer account via api or delete or save any information, the endpoint of API and payload with complete details is mentioned.

List of customer APIs that are available in Magento 2 default.

  1. Group APIs of Customer
  2. Metadata APIs of Customer
  3. Customer Address Metadata APIs
  4. Magento 2 Customer Account APIs
  5. Addresses APIs for Customer

 

Checkout REST APIs List in Magento 2

How do you add to the cart through REST API for Magento 2 customers? Perform an action for all the functionalities of the mini cart like update the price, update the content, or arrive at the checkout, its API endpoint indexed here As stated.

Receive data or save data on the checkout page, update price, or place an order.

To perform all these processes through the API, you will get a list that is prepared like a dictionary.

You won't need to do much research, everything is explained in step by step order.

This checkout API's default index is created so that any developer can easily use this list to create their own mobile application

  1. Shipping guest information
  2. My shipping information
  3. Shipping information
  4. Totals information
  5. Guest totals information
  6. Managing My totals information
  7. Guest place order with payment information saving
  8. My place order with payment information saving
  9. Get payment information
  10. Managing payment guest information
  11. My payment information

 

References

https://magento.stackexchange.com/

https://devdocs.magento.com/

Edit Multiple Customer Address With Magento 2 REST API

In this post, I am going to explain to you how to edit or update customer multiple addresses by customer address id using rest api in magento 2.

You just have to use the address id in order to edit the customer address.

So in the first step, we have to get the customer address id, and then we can use that id to edit the address.

 

Step 1: Get Customer Address ID API

By using this rest api we will get the customer address details that will help us to edit the customer address.

If a customer has five shipping addresses then each address will have an id.

Whenever we need to change the customer address then we have to edit by its address id.

Endpoint:

<host>/rest/default/V1/customers/customersID

Example:

https://wishusucess.com/rest/default/V1/customers/111

Method: GET

Headers:

  • Authorization: Bearer <admin_token>
  • Content-Type: application/json

Payload:

Not required

Edit Multiple customer address api
Customer Information

Response:

{
"id": 111,
"group_id": 4,
"default_billing": "281",
"default_shipping": "281",
"created_at": "2021-12-24 12:03:06",
"updated_at": "2022-02-24 08:57:48",
"created_in": "Default Store View",
"email": "cs.hemantsingh@gmail.com",
"firstname": "Hemant",
"lastname": "Singh",
"middlename": "Singh",
"gender": 0,
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 217,
"customer_id": 111,
"region": {
"region_code": "NY",
"region": "New York",
"region_id": 43
},
"region_id": 43,
"country_id": "US",
"street": [
"Add",
"Add2"
],
"telephone": "1234567890",
"postcode": "98761",
"city": "New York",
"firstname": "Hemant",
"lastname": "Singh"
},
{
"id": 226,
"customer_id": 111,
"region": {
"region_code": null,
"region": null,
"region_id": 0
},
"region_id": 0,
"country_id": "IN",
"street": [
"201301, Noida"
],
"telephone": "01710676441",
"postcode": "203301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh"
},
{
"id": 230,
"customer_id": 111,
"region": {
"region_code": null,
"region": null,
"region_id": 0
},
"region_id": 0,
"country_id": "IN",
"street": [
"201302, Noida"
],
"telephone": "777777777",
"postcode": "203302",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh"
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
},
"custom_attributes": [
{
"attribute_code": "customer_account_status",
"value": "1"
},
{
"attribute_code": "payment_status",
"value": "1"
}
]
}

 

Step 2: Edit Customer Shipping Address By Address ID

Now by sending the payload with customer address details we can edit/update customers' multiple addresses.

I am telling you about the Rest API on you, using which you can now change the address information of the customer.

One of the drawbacks of Magento's default customer edit API is that if you edit an address, all the rest of the addresses at once are removed and converted into a single address.

So you will need to do some customization which I have given in the link below.

Endpoint:

https://wishusucess.com/rest/V1/customers/111

Method: PUT

Headers:

  • Authorization: Bearer <admin_token>
  • Content-Type: application/json

Payload:

{
"customer": {
"firstname": "Hemant",
"lastname": "Singh",
"store_id": 1,
"website_id": 1,
"addresses": [{
"id": 217,
"customerId": 111,
"region": {
"region_code": "UP",
"region": "UttarPradesh"
},
"region_id": 566,
"countryId": "IN",
"street": [
"Saradarpur Colony"
],
"telephone": "8197565002",
"postcode": "201301",
"city": "Noida",
"defaultShipping": false,
"defaultBilling": true
}]
}
}

Edit Customer Multiple Address API

Response:

{
"id": 111,
"group_id": 4,
"default_billing": "217",
"created_at": "2021-12-24 12:03:06",
"updated_at": "2022-02-26 20:01:34",
"created_in": "Default Store View",
"email": "cs.hemantsingh@gmail.com",
"firstname": "Hemant8",
"lastname": "Singh",
"middlename": "Singh",
"gender": 0,
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 217,
"customer_id": 111,
"region": {
"region_code": "UP",
"region": "Uttar Pradesh",
"region_id": 566
},
"region_id": 566,
"country_id": "IN",
"street": [
"Sardarpur Colony"
],
"telephone": "8197565002",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
},
"custom_attributes": [
{
"attribute_code": "customer_account_status",
"value": "1"
},
{
"attribute_code": "payment_status",
"value": "1"
}
]
}

 

Update Address API by Address ID

Using this REST API in Magento 2, you can edit multiple addresses at once.

If there are 5 addresses added to a customer account, then all five customers' addresses can update the shipping address simultaneously with respect to the address ID.

This API can be used to change the shipping address information address of any customer.

Edit Customer Address Api

First, you have to download the customer edit address by address id rest api from Wishusucess GitHub repository then install it into your store, and then follow the below endpoint.

Endpoint:

https://wishusucess.com/rest/V1/addresses

Method: POST

Headers:

  • Authorization: Bearer <admin_token>
  • Content-Type: application/json

Payload:

{
"address": {
"id": "7",
"customer_id": "3",
"firstname": "Hemant",
"lastname": "Singh",
"street": [
"Street 1"
],
"telephone": "01234 56789",
"postcode": "201301",
"city": "Noida",
"defaultBilling": true,
"country_id": "IN"
}
}

Save Customer Address REST API
Update Customer Address

Response:

{
"id": 302,
"customer_id": 111,
"region": {
"region_code": "UP",
"region": "Uttar Pradesh",
"region_id": 566
},
"region_id": 566,
"country_id": "IN",
"street": [
"Street 1"
],
"telephone": "01234 56789",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh"
}

 

Conclusion:

We can edit or update customer address information by using the above rest api in Magento 2.

Firstly we have to get the address id then we can use that id to edit/update customer addresses by address id.

 

Read more: Magento 2.4 Installation Guide: How to Install Magento 2.4.2

Update Customer Attributes Value via Magento 2 REST API

I am explaining to you to update customer attributes value based on the customer id through rest API in Magento 2.

When a customer orders a product in the Magento store, then payment status get changes, and if the customer has come after registering, then his account status also changes.

So to change the value of the attributes of the customer through Magento 2 REST API it is necessary to hit its correct endpoint.

The customer needs to send their payload details to update the custom attribute value.

The status is updated only by the correct value in the body which is given below.

The same API is also used to add or change the data of the attribute of the customer based on the customer id.

Admin > Customer > Customer Account > Account Information

Update Customer Attributes Value
Customer Attributes Change Status

 

 

Change Customer Account Status in Magento 2

If you want to change any value of a customer's account information like want to change the name, want to change the last name, change email id, change the date of birth, change gender or change address, change order status.

To change all these data through Magento 2 default rest api you can get detailed information by add/update customer data by rest api.

 

Update Customer Attributes Value REST API

The customer attribute whose value is to be changed can be changed by the endpoint given below.

First of all, by entering that attribute in the body, you have to hit it. Then you will get the changed value in the response.

store_url://domin_name/rest/V1/customers/customerID

Endpoint:

https://wishusucess.com/rest/V1/customers/111

Method: PUT

Header:

  • Authorization: Bearer admin_token
  • Content-Type: Application/Json

Body:

{ "customer": {
"custom_attributes": [
{
"attribute_code": "customer_account_status",
"value": "1"
},
{
"attribute_code": "payment_status",
"value": "1"
}
]
}
}

Update Attributes API
Update Attributes on Postman

 

Response:

{
"id": 111,
"group_id": 4,
"default_billing": "281",
"default_shipping": "281",
"created_at": "2021-12-24 12:03:06",
"updated_at": "2022-02-22 13:19:30",
"created_in": "Default Store View",
"email": "cs.hemantsingh@gmail.com",
"firstname": "Hemant",
"lastname": "Singh",
"middlename": "Singh",
"gender": 0,
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 217,
"customer_id": 111,
"region": {
"region_code": "UP",
"region": "Uttar Pradesh",
"region_id": 566
},
"region_id": 56,
"country_id": "IN",
"street": [
"Noida",
"Noida"
],
"telephone": "1234567890",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh"
},
{
"id": 281,
"customer_id": 111,
"region": {
"region_code": "UP",
"region": "Uttar Pradesh",
"region_id": 566
},
"region_id": 566,
"country_id": "IN",
"street": [
"PMO Apartment"
],
"telephone": "08197565002",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"default_shipping": true,
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
},
"custom_attributes": [
{
"attribute_code": "customer_account_status",
"value": "1"
},
{
"attribute_code": "payment_status",
"value": "1"
}
]
}

 

Read more: Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

Conclusion:

You can use this magento 2 rest api to update any kind of customer-related details or value of the custom attributes.

Through this, you can change the payment status, if you want, you can change the account status for the customer.

To update its name, email id, etc. details, by this you can update the value of any customer parameter.

 

Recommended Posts:

Add/Update Many Customer Address REST API in Magento 2

Add Multiple Customer Address via Magento 2 REST API

 

Add/Update Many Customer Address REST API in Magento 2

In this post, I am explaining to you to add/update many customer addresses via Magento 2 customer address rest api.

When we have to add multiple addresses at once through REST API, we cannot add the customer address through the default API of Magento 2.

For how to add a new customer address using api in Magento 2 we have to use the endpoint URL {store_url}/rest/V1/address and POST Action method.

 

Magento 2 REST API Add/Update Many Customer Address

Magento 2 Add a New Customer Address API help you to add as many addresses for a single customer without updating the old address.

I'm explaining to you by web API module to add a new customer address using Magento 2 REST API.

Endpoint:

https://wishusucess.com/rest/V1/addresses/

Method: POST

Header:

 

Step 1: Registration of Customer API

In the first step of adding/updating the customer address via Magento 2 rest API, we have to register the module via the registration.php file.

Wishusucess/AddAddress/registration.php
<?php
/*
* Developer: Magento 2x Developer Hemant Kumar Singh
* Category: Customer REST API
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_AddAddress',
__DIR__
);

 

Step 2: Create Module File

In this step, we have to give the basic information of our edit information of customer using api.

Wishusucess/AddAddress/etc/module.xml
<?xml version="1.0"?>
<!--
/*
* Developer: Magento 2x Developer Hemant Kumar Singh
* Category: Customer REST API
*/ 
--> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Wishusucess_AddAddress" setup_version="1.0.0" schema_version="1.0.0">
</module>
</config>

 

Step 3: Routing of Add/Update Customer API

Now in this step, we have to define the route id via a web API XML file. This file has all the details of routing and the method that we have to select while hitting the endpoint.

Wishusucess/AddAddress/etc/webapi.xml
<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<!-- Routing define -->
<route url="/V1/addresses" method="POST">
<service class="Magento\Customer\Api\AddressRepositoryInterface" method="save"/>
<resources>
<resource ref="Magento_Customer::manage"/>
</resources>
</route>
</routes>

 

Check-in body and response detail about Add Multiple Customer Address via Magento 2 REST API

 

Edit Customer Address REST API in Magento 2

Now in order to update the customer address, you have to create a rest API.

Add/Update Many Customer Address
Edit Customer Address

Below are the details of editing customer addresses using rest API for a magento 2 store.

You can get the body details

Endpoint:

https://wishusucess.com/rest/V1/addresses/

Method: POST

Header:

  • Authorization: Bearer Admin_Token
  • Content-Type: application/json

 

Step 1: Register Update Address API

Wishusucess/UpdateAddress/registration.php
<?php
/*
* Developer: Magento 2x Developer Hemant Kumar Singh
* Category: Customer REST API
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_UpdateAddress',
__DIR__
);

 

Step 2: Create Module File for API

Wishusucess/UpdateAddress/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Wishusucess_UpdateAddress" setup_version="1.0.0" schema_version="1.0.0">
</module>
</config>

 

Step 3: Create Web API XML File

Wishusucess/UpdateAddress/webapi.xml
<?xml version="1.0"?>
<routes
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/addresses" method="POST">
<service class="Magento\Customer\Api\AddressRepositoryInterface" method="save"/>
<resources>
<resource ref="Magento_Customer::manage"/>
</resources>
</route>
</routes>

 

Read more: What should be the body details to Update Customer address with REST API in Magento 2.

 

Conclusion:

To add or update the customer address of Magento 2 you need to create a custom web api as mentioned above.

Using this module you can add any number of addresses for the customer or you can use the rest api to edit it.

Add Multiple Customer Address via Magento 2 REST API

You have to implement a module to add multiple customer address for customers in Magento 2 store through rest api

This feature is not available in Magento 2 default REST API which can be used to add multiple customer addresses at once.

For this, I will explain to you to step by step method how you can save more than one customer address through API by implementing an extension.

 

Add Multiple Customer Address via REST API

As you can see on the screen below, this is the customer dashboard of the Magento 2.4 store.

Here the customer can save many addresses for himself, but the API for this is not available by default.

For this you will have to add some code, then by using it, you can save the data through API or

Add Multiple Customer Address

 

 

Step 1: Get Admin Token

First of all, you have to get an admin token then add that token as a header in Next API and send it along with.

Endpoint:

https://wishusucess.com/rest/V1/integration/admin/token

Method: POST

Body:

{
"username":"admin45",
"password":"Ainy@#13"
}

Response:

eiv9xouqxyxrasuz344k2azf2w6jtjsw

 

Step 2: Get Customer ID Using Customer Email

In the second step, we have to get the customer id detail by using email id via rest api.

In order to get the customer id via email id, you have to create a webapi route so you have to create a module also.

Endpoint:

https://wishusucess.com/rest/V1/getcustomerloginidusingemail

Method: POST

Header:

  • Content-Type: application/json
  • Authorization = Bearer admin_token

Body:

{"email":"cs.hemantsinghtech9@gmail.com"}

Response:

111

 

Step 3: Add Multiple Customer Address Using REST API

Now you can save the multiple customer addresses by using the below customer add address rest api in Magento 2.

So you have to send the address detail in the body along with the customer id.

You can get this below rest api extension via following the link of add/update many customer addresses via REST API in Magento 2.

Endpoint:

https://wishusucess.com/rest/V1/addresses

Method: POST

Header:

  • Authorization: Bearer <Admin Token>
  • Content-Type: Application/json

Body:

{
"address": { 
"customer_id": "111",
"defaultShipping": true,
"defaultBilling": true,
"region": "India",
"country_id": "IN",
"street": [ "201302, Noida" ],
"postcode": "203302",
"city": "Noida",
"firstname": "Hemant23",
"lastname": "Singh34", 
"telephone": "77777777777",
"countryId": "IN"
}
}

Save Customer Address via API
Save Customer Address via API

 

Response:

{
"id": 230,
"customer_id": 111,
"region": {
"region_code": null,
"region": null,
"region_id": 0
},
"region_id": 0,
"country_id": "IN",
"street": [
"201302, Noida"
],
"telephone": "77777777777",
"postcode": "203302",
"city": "Noida",
"firstname": "Hemant23",
"lastname": "Singh34"
}

 

Read more: Elasticsearch: How to Install Elasticsearch in Ubuntu 18.04

 

Conclusion:

As you can see in the details, we can do whatever address is to be saved through Rest API.

For that, we will need to write some custom code which we have told you in this post.

Using the above-mentioned details, you can save any number of addresses for the customer through Test API.

Magento 2 Payment API: Make Payment Using REST API

In this post, I will explain to you step-by-step methods to pay for any product through Magento 2 Payment API.

While making payment you can select the payment method like if you want to make cash on delivery (COD) payment then which API will be hit or if you want to make cash memo payment then which rest API will be used for that.

Through this post, we will also know that if you want to make a PayPal payment, then which API will be used for that.

I am explaining below the details of the steps to use all these payment APIs.

 

Create Order from Admin Dashboard via REST API

If you want to create an order through rest API from Magento 2 Admin Dashboard, then you will also have to complete payment for that.

When your payment is complete, the newly created order will appear in this dashboard.

Create Order From Admin via REST API

You can create an order directly from the sales admin dashboard using this rest api.

Admin > Sales > Order > Create New Order

 

Magento 2 Payment API for Guest Customer

You have to execute the below-mentioned four REST APIs step by step then only you will be able to complete the payment for the guest customers.

Guest customers can select and pay through the available payment options.

You can make payment based on whatever payment method available in your store like cash on delivery case money order paper payment etc.

Step 1

http://m243p1s.com/index.php/rest/V1/guest-carts/

Step 2

http://m243p1s.com/index.php/rest/V1/guest-carts/quote_id/items

Step 3

http://m243p1s.com/index.php/rest/V1/guest-carts/quote_id

Step 4

http://m243p1s.com/index.php/rest/V1/guest-carts/quote_id/shipping-information

If you want to know the above four steps in detail, then you can see our separate post for guest cart PayPal payment steps.

 

Step 5: Check Money Order Payment REST API

Payload:

http://m243p1s.com/index.php/rest/V1/guest-carts/quote_id/order

Method: PUT

Header:

  • Content-type = application/json

Body:

{ "paymentMethod": { "method": "checkmo" } }
Magento 2 Payment API
Now if you will go into the admin dashboard section then you can see the order has been created.
Created order Via API in dashboard

Cash On Delivery Payment REST API in Magento 2

Now if you want to make cash on delivery payment, then for that you have to follow the above-mentioned four states similarly.

If the guest wants to checkout, the steps will remain the same.

If you want to check out for Login Customer, then you can check the add to cart for login customer rest API to see other steps of Login Customer.

This is a final step that can be used to make payment by making payment through Cas on Delivery payment option via API in Magento 2.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/DUaFoHjVIQtfRk4W2xanZcVYTRhy4xav/shipping-information

Method: POST

Header:

  • Content-type = application/json

Now if you hit the above rest API Magento 2 gives you the response as a list of available payment methods, along with the total cart and details.

Magento 2 Payment API

 

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/DUaFoHjVIQtfRk4W2xanZcVYTRhy4xav/order

Method: PUT

Body:

{ "paymentMethod": { "method": "cashondelivery" } }

Cash on delivery payment via REST API

 

 

Conclusion:

You can order the product for the guest customer and also complete the payment.

For this, you will need to hit at least four REST APIs, and based on the quote id, you can place the order of the product.

 

Read more: Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

Magento 2 Get Shipping Information Details Via REST API

I am going to explain to you in detail to get the Shipping Information Details available in the Magento 2 store through rest api.

Through this API you can easily get the shipping information details available on any Magento 2 website.

You can also get the idea about what would be the endpoint of that API, What methods will we use when we hit the API and what should be its body details and what payloads should be sent.

You will get all these details through the rest API post in detail.

 

Magento 2 Get Shipping Information Details API

By using the following endpoint you can get the shipping information details through this rest API in Magento 2 store.

Before reaching this step we need to add some items inside our cart then after that, we will process our order toward the checkout.

  1. Estimate shipping costs
  2. Set shipping and billing information
  3. Estimate shipping costs

There is a separate cost for each shipping method which is calculated at the time of checkout of the order.

When we move towards check out, adding this cost inside the subtotal gives us the final price.

Through this post, we will get those steps with detailed information.

 

Endpoint:

https://www.your_domain_name.com/V1/guest-carts/<cartId>/estimate-shipping-methods

Headers:

  • Content-Type: application/json
  • Authorization: Bearer <customer token>

Payload:

{
"address": {
"region": "Uttar Pradesh",
"region_id": 566,
"region_code": "UP",
"country_id": "IN",
"street": [
"Noida"
],
"postcode": "302022",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"customer_id": 111,
"email": "cs.hemantsingh@gmail.com",
"telephone": "(512) 555-1111",
"same_as_billing": 1
}
}

 

Response:

When we calculate the price at the checkout step of a product order, some other charges like shipping method charges flat-rate shipping, fixed price, etc. are also included.

But this charge is not applicable for downloadable products as the customer downloads the same.

Because this product does not need to be delivered, due to that shipping charges are not levied.

[
{
"carrier_code": "flatrate",
"method_code": "flatrate",
"carrier_title": "Flat Rate",
"method_title": "Fixed",
"amount": 15,
"base_amount": 15,
"available": true,
"error_message": "",
"price_excl_tax": 15,
"price_incl_tax": 15
},
{
"carrier_code": "tablerate",
"method_code": "bestway",
"carrier_title": "Best Way",
"method_title": "Table Rate",
"amount": 5,
"base_amount": 5,
"available": true,
"error_message": "",
"price_excl_tax": 5,
"price_incl_tax": 5
}
]

 

Steps to Save Shipping And Billing Information Via API

Now you can save both shipping address and billing address by using the following endpoint.

For this, you have to hit on the below endpoint and send a payload.

Inside that payload, you will mention both your shipping address and billing address and also send the customer token as authorization inside the header.

You have to also select carrier_code and method_code along with shipping and billing details in the payload.

Now the pricing will be calculated as a total and sent you the response of the order along with the payment method.

 

Read more: Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

Guest Carts Endpoint:

https://www.your_domin_name.com/V1/guest-carts/<cartId>/shipping-information

This guest cart endpoint will help you to set the billing and shipping information on behalf of a guest.

Login Customer Endpoint:

https://www.your_domin_name.com/<host>/rest/<store_code>/V1/carts/mine/shipping-information

Method: POST

Headers:

  • Content-Type: application/json
  • Authorization: Bearer <customer token>

Body Payload:

{
"addressInformation": {
"shipping_address": {
"region": "Uttar Pradesh",
"region_id": 566,
"region_code": "UP",
"country_id": "566",
"street": [
"Noida"
],
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"email": "cs.hemantsingh@gmail.com",
"telephone": "7992293862"
},
"billing_address": {
"region": "Uttar Pradesh",
"region_id": 566,
"region_code": "UP",
"country_id": "IN",
"street": [
"Noida"
],
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"email": "cs.hemantsingh@gmail.com",
"telephone": "7992293862"
},
"shipping_carrier_code": "tablerate",
"shipping_method_code": "bestway"
}
}

Response:

Now Magento store will send you the subtotal of the order, including shipping charges. Now the grand total will be subtotal+shipping charge.

The available payment method enabled inside the Magento 2 website will be shown to you as a response, you can make the payment using that payment method.

Shipping Information Detail

{
"payment_methods": [
{
"code": "cashondelivery",
"title": "Cash On Delivery"
},
{
"code": "banktransfer",
"title": "Bank Transfer Payment"
},
{
"code": "purchaseorder",
"title": "Purchase Order"
},
{
"code": "checkmo",
"title": "Check / Money order"
}
],
"totals": {
"grand_total": 165,
"base_grand_total": 165,
"subtotal": 160,
"base_subtotal": 160,
"discount_amount": 0,
"base_discount_amount": 0,
"subtotal_with_discount": 160,
"base_subtotal_with_discount": 160,
"shipping_amount": 5,
"base_shipping_amount": 5,
"shipping_discount_amount": 0,
"base_shipping_discount_amount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"weee_tax_applied_amount": null,
"shipping_tax_amount": 0,
"base_shipping_tax_amount": 0,
"subtotal_incl_tax": 160,
"shipping_incl_tax": 5,
"base_shipping_incl_tax": 5,
"base_currency_code": "USD",
"quote_currency_code": "USD",
"items_qty": 4,
"items": [
{
"item_id": 6,
"price": 22,
"base_price": 22,
"qty": 1,
"row_total": 22,
"base_row_total": 22,
"row_total_with_discount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"tax_percent": 0,
"discount_amount": 0,
"base_discount_amount": 0,
"discount_percent": 0,
"price_incl_tax": 22,
"base_price_incl_tax": 22,
"row_total_incl_tax": 22,
"base_row_total_incl_tax": 22,
"options": "[]",
"weee_tax_applied_amount": null,
"weee_tax_applied": null,
"name": "Radiant Tee-M-Orange"
},
{
"item_id": 7,
"price": 18,
"base_price": 18,
"qty": 1,
"row_total": 18,
"base_row_total": 18,
"row_total_with_discount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"tax_percent": 0,
"discount_amount": 0,
"base_discount_amount": 0,
"discount_percent": 0,
"price_incl_tax": 18,
"base_price_incl_tax": 18,
"row_total_incl_tax": 18,
"base_row_total_incl_tax": 18,
"options": "[{\"value\":\"Advanced Pilates & Yoga (Strength)\",\"label\":\"Downloads\"}]",
"weee_tax_applied_amount": null,
"weee_tax_applied": null,
"name": "Advanced Pilates & Yoga (Strength)"
},
{
"item_id": 8,
"price": 68,
"base_price": 68,
"qty": 1,
"row_total": 68,
"base_row_total": 68,
"row_total_with_discount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"discount_amount": 0,
"base_discount_amount": 0,
"discount_percent": 0,
"price_incl_tax": 68,
"base_price_incl_tax": 68,
"row_total_incl_tax": 68,
"base_row_total_incl_tax": 68,
"options": "[{\"value\":\"1 x Sprite Stasis Ball 65 cm <span class=\\\"price\\\">$27.00<\\/span>\",\"label\":\"Sprite Stasis Ball\"},{\"value\":\"1 x Sprite Foam Yoga Brick <span class=\\\"price\\\">$5.00<\\/span>\",\"label\":\"Sprite Foam Yoga Brick\"},{\"value\":\"1 x Sprite Yoga Strap 8 foot <span class=\\\"price\\\">$17.00<\\/span>\",\"label\":\"Sprite Yoga Strap\"},{\"value\":\"1 x Sprite Foam Roller <span class=\\\"price\\\">$19.00<\\/span>\",\"label\":\"Sprite Foam Roller\"}]",
"weee_tax_applied_amount": null,
"weee_tax_applied": null,
"name": "Sprite Yoga Companion Kit"
},
{
"item_id": 13,
"price": 52,
"base_price": 52,
"qty": 1,
"row_total": 52,
"base_row_total": 52,
"row_total_with_discount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"tax_percent": 0,
"discount_amount": 0,
"base_discount_amount": 0,
"discount_percent": 0,
"price_incl_tax": 52,
"base_price_incl_tax": 52,
"row_total_incl_tax": 52,
"base_row_total_incl_tax": 52,
"options": "[{\"value\":\"Gray\",\"label\":\"Color\"},{\"value\":\"S\",\"label\":\"Size\"}]",
"weee_tax_applied_amount": null,
"weee_tax_applied": null,
"name": "Chaz Kangeroo Hoodie"
}
],
"total_segments": [
{
"code": "subtotal",
"title": "Subtotal",
"value": 160
},
{
"code": "shipping",
"title": "Shipping & Handling (Best Way - Table Rate)",
"value": 5
},
{
"code": "tax",
"title": "Tax",
"value": 0,
"extension_attributes": {
"tax_grandtotal_details": []
}
},
{
"code": "grand_total",
"title": "Grand Total",
"value": 165,
"area": "footer"
}
]
}
}

 

Verify This Steps

Now, in order to verify this is to get the details you have to log in as a customer of the Magento 2 store and then go to the checkout page.

You can see that the payment method and other details in which you have saved the data through REST API are showing.

 

Conclusion:

It is possible to save shipping information or gate payment information through REST API.

You can get the shipping method details of any customer through the above-mentioned API and save shipping details.

 

Recommended Posts:

Guest Cart Paypal Payment Steps: Magento 2 REST API

Get Customer Detail Using Email ID in Magento 2 REST API

Guest Cart Paypal Payment Steps: Magento 2 REST API

In this post, I am going to explain how to perform guest cart Paypal payment steps in Magento 2 application.

Paying an amount in the Magento 2 store through a guest customer account is essential or improves your customer experience.

Paying via PayPal Payments inside the Magento store is also an important part for guest customers.

Through this post, we will go to know how to add items inside cutout for any guest customer and save shipping information and how to do any payment.

 

Magento 2 Guest Cart PayPal Payment Steps

Checking out guest customers for the Magento website is required for mobile applications.

Through this post, we will tell the guest customer the steps to add an item cart through rest api then save shipping information inside it using rest API.

In the last step, the guest customer will make the payment via PayPal payment at the checkout page to make the payment using the REST API.

Then after the PayPal payment is completed, it will also show the massage of its response on the success page.

 

Read more: Configure PayPal in Magento 2 : How to Integrate PayPal

 

Step 1: Get Admin Access Token

In the first step, the admin will get the access token of the login, then in the second step, the access token will be used.

To get the access token we will send admin details of the Magento store ie admin user and password inside the body and in return, we will get an access token.

Endpoint:

https://wishusucess.com/rest/V1/integration/admin/token

Method: POST

Header: Not required

Get Admin Access Token

Response:

rw1y20up27hrzcu1l6lp4t6uitsnczag

 

Step 2: Create Empty Cart for The Guest Customer

Now using the admin access token we will create an empty card for the guest customer.

Then we will get a quote id for a guest card through this API as a response.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/

Method: POST

Header: Not required

Guest Cart PayPal Payment Steps

Response:

hQDMOwbCqcub25qSfQccL3bFLTsDGSaC

 

Step 3: Add or Update Items in Cart

The REST API we hit in the second step yielded a quote ID.

Quote ID will be used for Add to Cart Items or Update Items of Guest Cart of Guest Customer.

To add cart item, inside the body will send the quote id as well as product details like SKU item quantity, etc.

In the header, the admin token will also be sent for authorization.

Now we will hit the guest customer add to cart Rest API, after that, we will get the response and in that response, the item which we mentioned in the body will be added.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/w2CFwWlzAkhnym999IBdQl8LBp9r6sdE/items

Method: POST

Header:

  • Content-Type: application/json
  • Authorization: Bearer Admin_Token

Body: 

{ "cartItem": { "quote_id": "w2CFwWlzAkhnym999IBdQl8LBp9r6sdE", "sku": "accessories1231", "qty": 1 } }

Add Update Cart Item REST API

 

Step 4: Get The Cart Details

Now we will hit by adding the quote id to the end of the rest API. We will get the cart detail of the guest customer using this api.

In this detail, you will get the product name, price, item ID, product type, etc. by using this cart detail Magento 2 rest API.

Endpoint

https://wishusucess.com/index.php/rest/V1/guest-carts/ewWBDaATec0fKEo15lZkGzEiaoZ1p6sh

Method: GET

Header:

  • Content-Type: application/json
  • Authorization: Bearer Admin_Token

Body: 

Not required

Get the Cart Details REST API

Response:

{
"id": 2271,
"created_at": "2022-02-11 06:22:24",
"updated_at": "2022-02-11 06:24:47",
"is_active": true,
"is_virtual": false,
"items": [
{
"item_id": 1009,
"sku": "accessories1231",
"qty": 1,
"name": "accessories mono c",
"price": 133,
"product_type": "simple",
"quote_id": "2271",
"extension_attributes": {
"image_url": "https://wishusucess.com/pub/media/catalog/product/cache/54139b022fb7bb8c324a752eac907829/b/a/bags_9.png"
}
}
],
"items_count": 1,
"items_qty": 1,
"customer": {
"email": null,
"firstname": null,
"lastname": null
},
"billing_address": {
"id": 4706,
"region": null,
"region_id": null,
"region_code": null,
"country_id": null,
"street": [
""
],
"telephone": null,
"postcode": null,
"city": null,
"firstname": null,
"lastname": null,
"email": null,
"same_as_billing": 0,
"save_in_address_book": 0
},
"orig_order_id": 0,
"currency": {
"global_currency_code": "USD",
"base_currency_code": "USD",
"store_currency_code": "USD",
"quote_currency_code": "USD",
"store_to_base_rate": 0,
"store_to_quote_rate": 0,
"base_to_global_rate": 1,
"base_to_quote_rate": 1
},
"customer_is_guest": false,
"customer_note_notify": true,
"customer_tax_class_id": 3,
"store_id": 1,
"extension_attributes": {
"shipping_assignments": [
{
"shipping": {
"address": {
"id": 4707,
"region": null,
"region_id": null,
"region_code": null,
"country_id": null,
"street": [
""
],
"telephone": null,
"postcode": null,
"city": null,
"firstname": null,
"lastname": null,
"email": null,
"same_as_billing": 1,
"save_in_address_book": 0
},
"method": null
},
"items": [
{
"item_id": 1009,
"sku": "accessories1231",
"qty": 1,
"name": "accessories mono c",
"price": 133,
"product_type": "simple",
"quote_id": "2271",
"extension_attributes": {
"image_url": "https://wishusucess.com/pub/media/catalog/product/cache/54139b022fb7bb8c324a752eac907829/b/a/bags_9.png"
}
}
]
}
]
}
}

 

Step 5: Add Shipping Information to The Cart

Through this REST API, we will save the shipping address to which the product is to be delivered to the customer i.e. use this rectify to save the shipping address.

This REST API will serve to save the shipping address for the guest customer on the store.

When we will get the response, the payment methods available in the store will be shown in that response.

The kind of payment method that Magento store is providing will be visible as an available payment method response.

Now payment can be done by selecting that payment method in the next step.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/ewWBDaATec0fKEo15lZkGzEiaoZ1p6sh/shipping-information

Method: POST

Header:

  • Content-Type: application/json
  • Authorization: Bearer Admin_Token

Body: 

{
"addressInformation": {
"billingAddress": {
"region": "UP",
"region_id": 566,
"country_id": "IN",
"street": [
"Botanical Garden Metro, Noida"
],
"company": "Wishusucess",
"telephone": "1111111",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemamt",
"lastname": "Singh",
"email": "cs.hemantsingh@gmail.com",
"prefix": "address_",
"region_code": "UP"
},
"shippingAddress": {
"region": "UP",
"region_id": 566,
"country_id": "IN",
"street": [
"Botanical Garden Metro, Noida"
],
"company": "Wishusucess",
"telephone": "1111111",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"email": "cs.hemantsingh@gmail.com",
"prefix": "address_",
"region_code": "UP",
"sameAsBilling": 1
},
"shippingCarrierCode": "flatrate",
"shippingMethodCode": "flatrate"
}
}

Add Shipping Information for Guest Cart PayPal Payment Steps

Response:

{
"payment_methods": [
{
"code": "paypal_express",
"title": "PayPal Credit (Paypal Express)"
},
{
"code": "paypal_express",
"title": "PayPal Express Checkout"
}
],
"totals": {
"grand_total": 133,
"base_grand_total": 133,
"subtotal": 133,
"base_subtotal": 133,
"discount_amount": 0,
"base_discount_amount": 0,
"subtotal_with_discount": 133,
"base_subtotal_with_discount": 133,
"shipping_amount": 0,
"base_shipping_amount": 0,
"shipping_discount_amount": 0,
"base_shipping_discount_amount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"weee_tax_applied_amount": null,
"shipping_tax_amount": 0,
"base_shipping_tax_amount": 0,
"subtotal_incl_tax": 133,
"shipping_incl_tax": 0,
"base_shipping_incl_tax": 0,
"base_currency_code": "USD",
"quote_currency_code": "USD",
"items_qty": 1,
"items": [
{
"item_id": 1009,
"price": 133,
"base_price": 133,
"qty": 1,
"row_total": 133,
"base_row_total": 133,
"row_total_with_discount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"tax_percent": 0,
"discount_amount": 0,
"base_discount_amount": 0,
"discount_percent": 0,
"price_incl_tax": 133,
"base_price_incl_tax": 133,
"row_total_incl_tax": 133,
"base_row_total_incl_tax": 133,
"options": "[]",
"weee_tax_applied_amount": null,
"weee_tax_applied": null,
"name": "accessories mono c"
}
],
"total_segments": [
{
"code": "subtotal",
"title": "Subtotal",
"value": 133
},
{
"code": "shipping",
"title": "Shipping & Handling (By DEN - By DEN)",
"value": 0
},
{
"code": "tax",
"title": "Tax",
"value": 0,
"extension_attributes": {
"tax_grandtotal_details": []
}
},
{
"code": "grand_total",
"title": "Grand Total",
"value": 133,
"area": "footer"
}
]
}
}

 

Step 6: Add Payment Information And Place The Order

Now add the payment option in the body and hit the rest api.

You will get a response.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/ewWBDaATec0fKEo15lZkGzEiaoZ1p6sh/order

Method: PUT

Header:

  • Content-Type: application/json
  • Authorization: Bearer Admin_Token

Body: 

{ "paymentMethod": { "method": "paypal_express" } }

Payment Information API Magento 2

Response:

1

 

Step 7: Complete PayPal Payment - Guest Cart Paypal payment Steps

Now follow the below step to complete the transaction.

Now click on the link given below to complete your PayPal payment.

Then in the next step follow the step by step PayPal payment mentioned in the post

How to Make Payment Using PayPal REST API in Magento 2

 

 

Similar Posts:

Get Customer Detail Using Email ID in Magento 2 REST API

Get Customer Detail Using Email ID in Magento 2 REST API

When we make a mobile application, then we need many types of API at that time. In order to develop a mobile application, there is a Magento 2 Customer Detail REST API named order detail generation using email.

Whatever product is ordered on the magento2 eCommerce platform, if you want to extract that product order details using email id, then you can use the rest API given below.

If we want to get customer order details through email id, then you can easily get the detail via email id rest API.

Under the order details, all the payment details will be shown and the status of the order will show how many products you have ordered so far.

What is the status of your every order i.e. if ever your status has been successful then it will appear as successful and if your order was pending or you have canceled your order then that order will also show you in the response?

 

Get Order Detail REST API Magento 2

There are two ways to get the Magento 2 customer order details via rest API while developing the mobile application.

  • Get customer order detail via Email ID
  • Get customer detail via Order ID

Here, We will try to get the order details in both ways and check both the APIs alternately on postman.com to see what response we are getting.

 

Magento 2 Get Customer Detail REST API Via Email ID

As you can see in the response below I have entered the customer email parameter id inside of REST API Prams and all the products ordered from this email id are easily visible in the response.

Total count is also showing via using this resp API, Payment information is also visible by whom the payment has been made and billing address shipping address is also visible.

You can also get the method used while ordering the product using order detail rest api.

Endpoint:

http://wishusucess.com/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=customer_email&searchCriteria[filter_groups][0][filters][0][value]=cs.hemantsingh@gmail.com

Method: GET

Header:

  • Authorization: bearer <admin_token>
  • content-type: application/json

Body:

Not Required

Customer Detail Using Email ID in Magento 2

 

Response:

{
"items": [
{
"base_currency_code": "USD",
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_grand_total": 200,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_shipping_amount": 0,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 0,
"base_shipping_invoiced": 0,
"base_shipping_tax_amount": 0,
"base_subtotal": 200,
"base_subtotal_incl_tax": 200,
"base_subtotal_invoiced": 200,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"base_total_due": 0,
"base_total_invoiced": 200,
"base_total_invoiced_cost": 0,
"base_total_paid": 200,
"base_to_global_rate": 1,
"base_to_order_rate": 1,
"billing_address_id": 198,
"created_at": "2022-01-13 06:46:19",
"customer_email": "cs.hemantsingh@gmail.com",
"customer_group_id": 0,
"customer_is_guest": 1,
"customer_note_notify": 1,
"discount_amount": 0,
"discount_invoiced": 0,
"email_sent": 1,
"entity_id": 99,
"global_currency_code": "USD",
"grand_total": 200,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"increment_id": "000000138",
"is_virtual": 0,
"order_currency_code": "USD",
"protect_code": "a04608837596c6736a143b98497134a1",
"quote_id": 1110,
"remote_ip": "14.102.51.229",
"shipping_amount": 0,
"shipping_description": "By DEN - By DEN",
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 0,
"shipping_invoiced": 0,
"shipping_tax_amount": 0,
"state": "processing",
"status": "processing",
"store_currency_code": "USD",
"store_id": 1,
"store_name": "Main Website\nMain Website Store\nDefault Store View",
"store_to_base_rate": 0,
"store_to_order_rate": 0,
"subtotal": 200,
"subtotal_incl_tax": 200,
"subtotal_invoiced": 200,
"tax_amount": 0,
"tax_invoiced": 0,
"total_due": 0,
"total_invoiced": 200,
"total_item_count": 1,
"total_paid": 200,
"total_qty_ordered": 2,
"updated_at": "2022-01-13 06:47:13",
"weight": 200,
"x_forwarded_for": "14.102.51.229",
"items": [
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_original_price": 100,
"base_price": 100,
"base_price_incl_tax": 100,
"base_row_invoiced": 200,
"base_row_total": 200,
"base_row_total_incl_tax": 200,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2022-01-13 06:46:19",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 144,
"name": "Accessories monogram D",
"no_discount": 0,
"order_id": 99,
"original_price": 100,
"price": 100,
"price_incl_tax": 100,
"product_id": 17,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 2,
"qty_ordered": 2,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 568,
"row_invoiced": 200,
"row_total": 200,
"row_total_incl_tax": 200,
"row_weight": 200,
"sku": "Accessories monogram D",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2022-01-13 06:46:19",
"weee_tax_applied": "[]",
"weight": 100
}
],
"billing_address": {
"address_type": "billing",
"city": "Noida",
"country_id": "IN",
"email": "cs.hemantsingh@gmail.com",
"entity_id": 198,
"firstname": "Hemant",
"lastname": "Singh",
"parent_id": 99,
"postcode": "95070",
"region": "Uttar Pradesh",
"region_code": "UP",
"region_id": 566,
"street": [
"New test"
],
"telephone": null
},
"payment": {
"account_status": null,
"additional_information": [
"0",
"1",
"",
"TUZYUGM3ERY3Q",
"cs.hemantsingh@gmail.com",
"unverified",
"confirmed",
"133ea25fc4520",
"TUZYUGM3ERY3Q",
"EC-98T36492VK521913U",
"PayPal Express Checkout",
null,
"Eligible",
"completed",
"None"
],
"amount_authorized": 200,
"amount_ordered": 200,
"amount_paid": 200,
"base_amount_authorized": 200,
"base_amount_ordered": 200,
"base_amount_paid": 200,
"base_amount_paid_online": 200,
"base_shipping_amount": 0,
"base_shipping_captured": 0,
"cc_exp_year": "0",
"cc_last4": null,
"cc_ss_start_month": "0",
"cc_ss_start_year": "0",
"entity_id": 99,
"last_trans_id": "9LN125666F286773U",
"method": "paypal_express",
"parent_id": 99,
"shipping_amount": 0,
"shipping_captured": 0
},
"status_histories": [
{
"comment": "IPN \"Completed\" Registered notification about captured amount of $200.00. Transaction ID: \"<a target=\"_blank\" href=\"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=9LN125666F286773U\">9LN125666F286773U</a>\"",
"created_at": "2022-01-13 06:46:37",
"entity_id": 44,
"entity_name": "order",
"is_customer_notified": null,
"is_visible_on_front": 0,
"parent_id": 99,
"status": "processing"
},
{
"comment": "Captured amount of $200.00 online. Transaction ID: \"<a target=\"_blank\" href=\"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=9LN125666F286773U\">9LN125666F286773U</a>\"",
"created_at": "2022-01-13 06:46:19",
"entity_id": 43,
"entity_name": "invoice",
"is_customer_notified": null,
"is_visible_on_front": 0,
"parent_id": 99,
"status": "processing"
}
],
"extension_attributes": {
"shipping_assignments": [
{
"shipping": {
"address": {
"address_type": "shipping",
"city": "Noida",
"country_id": "IN",
"email": "cs.hemantsingh@gmail.com",
"entity_id": 197,
"firstname": "Hemant",
"lastname": "Singh",
"parent_id": 99,
"postcode": "302021",
"region": "Uttar Pradesh",
"region_code": "UP",
"region_id": 566,
"street": [
"New test"
],
"telephone": null
},
"method": "flatrate_flatrate",
"total": {
"base_shipping_amount": 0,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 0,
"base_shipping_invoiced": 0,
"base_shipping_tax_amount": 0,
"shipping_amount": 0,
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 0,
"shipping_invoiced": 0,
"shipping_tax_amount": 0
}
},
"items": [
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_original_price": 100,
"base_price": 100,
"base_price_incl_tax": 100,
"base_row_invoiced": 200,
"base_row_total": 200,
"base_row_total_incl_tax": 200,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2022-01-13 06:46:19",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 144,
"name": "Accessories monogram D",
"no_discount": 0,
"order_id": 99,
"original_price": 100,
"price": 100,
"price_incl_tax": 100,
"product_id": 17,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 2,
"qty_ordered": 2,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 568,
"row_invoiced": 200,
"row_total": 200,
"row_total_incl_tax": 200,
"row_weight": 200,
"sku": "Accessories monogram D",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2022-01-13 06:46:19",
"weee_tax_applied": "[]",
"weight": 100
}
]
}
],
"payment_additional_info": [
{
"key": "paypal_express_checkout_shipping_overridden",
"value": "0"
},
{
"key": "button",
"value": "1"
},
{
"key": "paypal_express_checkout_shipping_method",
"value": ""
},
{
"key": "paypal_payer_id",
"value": "TUZYUGM3ERY3Q"
},
{
"key": "paypal_payer_email",
"value": "cs.hemantsingh@gmail.com"
},
{
"key": "paypal_payer_status",
"value": "unverified"
},
{
"key": "paypal_address_status",
"value": "confirmed"
},
{
"key": "paypal_correlation_id",
"value": "133ea25fc4520"
},
{
"key": "paypal_express_checkout_payer_id",
"value": "TUZYUGM3ERY3Q"
},
{
"key": "paypal_express_checkout_token",
"value": "EC-98T36492VK521913U"
},
{
"key": "method_title",
"value": "PayPal Express Checkout"
},
{
"key": "paypal_express_checkout_redirect_required",
"value": "null"
},
{
"key": "paypal_protection_eligibility",
"value": "Eligible"
},
{
"key": "paypal_payment_status",
"value": "completed"
},
{
"key": "paypal_pending_reason",
"value": "None"
}
],
"applied_taxes": [],
"item_applied_taxes": []
}
}
],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "customer_email",
"value": "cs.hemantsingh@gmail.com",
"condition_type": "eq"
}
]
}
]
},
"total_count": 1
}

 

 

View Order By Order Id via Magento 2 REST API

Magento 2 provides a REST API to get the order detail like payment information, payment status, payment method, shipping address, billing address, etc. using order id.

If order detail information is to be retrieved on the basis of order id, then we will use order view via order id API for that.

Lastly, we will enter the order id and hit the API, then we will get all the details of the order as our response

Endpoint:

http://wishusucess.com/rest/V1/orders/99

Method: GET

  • Authorization: Bearer admin_token
  • Content-Type: application/json

Body:

Not required

Customer Detail REST API

Response:

{
"base_currency_code": "USD",
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_grand_total": 200,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_shipping_amount": 0,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 0,
"base_shipping_invoiced": 0,
"base_shipping_tax_amount": 0,
"base_subtotal": 200,
"base_subtotal_incl_tax": 200,
"base_subtotal_invoiced": 200,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"base_total_due": 0,
"base_total_invoiced": 200,
"base_total_invoiced_cost": 0,
"base_total_paid": 200,
"base_to_global_rate": 1,
"base_to_order_rate": 1,
"billing_address_id": 198,
"created_at": "2022-01-13 06:46:19",
"customer_email": "test456@tech9logy.in",
"customer_group_id": 0,
"customer_is_guest": 1,
"customer_note_notify": 1,
"discount_amount": 0,
"discount_invoiced": 0,
"email_sent": 1,
"entity_id": 99,
"global_currency_code": "USD",
"grand_total": 200,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"increment_id": "000000138",
"is_virtual": 0,
"order_currency_code": "USD",
"protect_code": "a04608837596c6736a143b98497134a1",
"quote_id": 1110,
"remote_ip": "14.102.51.229",
"shipping_amount": 0,
"shipping_description": "By DEN - By DEN",
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 0,
"shipping_invoiced": 0,
"shipping_tax_amount": 0,
"state": "processing",
"status": "processing",
"store_currency_code": "USD",
"store_id": 1,
"store_name": "Main Website\nMain Website Store\nDefault Store View",
"store_to_base_rate": 0,
"store_to_order_rate": 0,
"subtotal": 200,
"subtotal_incl_tax": 200,
"subtotal_invoiced": 200,
"tax_amount": 0,
"tax_invoiced": 0,
"total_due": 0,
"total_invoiced": 200,
"total_item_count": 1,
"total_paid": 200,
"total_qty_ordered": 2,
"updated_at": "2022-01-13 06:47:13",
"weight": 200,
"x_forwarded_for": "14.102.51.229",
"items": [
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_original_price": 100,
"base_price": 100,
"base_price_incl_tax": 100,
"base_row_invoiced": 200,
"base_row_total": 200,
"base_row_total_incl_tax": 200,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2022-01-13 06:46:19",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 144,
"name": "Accessories monogram D",
"no_discount": 0,
"order_id": 99,
"original_price": 100,
"price": 100,
"price_incl_tax": 100,
"product_id": 17,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 2,
"qty_ordered": 2,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 568,
"row_invoiced": 200,
"row_total": 200,
"row_total_incl_tax": 200,
"row_weight": 200,
"sku": "Accessories monogram D",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2022-01-13 06:46:19",
"weee_tax_applied": "[]",
"weight": 100
}
],
"billing_address": {
"address_type": "billing",
"city": "Noida",
"country_id": "US",
"email": "cs.hemantsingh@gmail.com",
"entity_id": 198,
"firstname": "Hemant",
"lastname": "Singh",
"parent_id": 99,
"postcode": "302021",
"region": "Uttar Pradesh",
"region_code": "UP",
"region_id": 566,
"street": [
"New test"
],
"telephone": null
},
"payment": {
"account_status": null,
"additional_information": [
"0",
"1",
"",
"TUZYUGM3ERY3Q",
"cs.hemantsingh@gmail.com",
"unverified",
"confirmed",
"133ea25fc4520",
"TUZYUGM3ERY3Q",
"EC-98T36492VK521913U",
"PayPal Express Checkout",
null,
"Eligible",
"completed",
"None"
],
"amount_authorized": 200,
"amount_ordered": 200,
"amount_paid": 200,
"base_amount_authorized": 200,
"base_amount_ordered": 200,
"base_amount_paid": 200,
"base_amount_paid_online": 200,
"base_shipping_amount": 0,
"base_shipping_captured": 0,
"cc_exp_year": "0",
"cc_last4": null,
"cc_ss_start_month": "0",
"cc_ss_start_year": "0",
"entity_id": 99,
"last_trans_id": "9LN125666F286773U",
"method": "paypal_express",
"parent_id": 99,
"shipping_amount": 0,
"shipping_captured": 0
},
"status_histories": [
{
"comment": "IPN \"Completed\" Registered notification about captured amount of $200.00. Transaction ID: \"<a target=\"_blank\" href=\"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=9LN125666F286773U\">9LN125666F286773U</a>\"",
"created_at": "2022-01-13 06:46:37",
"entity_id": 44,
"entity_name": "order",
"is_customer_notified": null,
"is_visible_on_front": 0,
"parent_id": 99,
"status": "processing"
},
{
"comment": "Captured amount of $200.00 online. Transaction ID: \"<a target=\"_blank\" href=\"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=9LN125666F286773U\">9LN125666F286773U</a>\"",
"created_at": "2022-01-13 06:46:19",
"entity_id": 43,
"entity_name": "invoice",
"is_customer_notified": null,
"is_visible_on_front": 0,
"parent_id": 99,
"status": "processing"
}
],
"extension_attributes": {
"shipping_assignments": [
{
"shipping": {
"address": {
"address_type": "shipping",
"city": "Noida",
"country_id": "IN",
"email": "cs.hemantsingh@gmail.com",
"entity_id": 197,
"firstname": "Hemant",
"lastname": "Singh",
"parent_id": 99,
"postcode": "302021",
"region": "Uttar Pradesh",
"region_code": "UP",
"region_id": 566,
"street": [
"New test"
],
"telephone": null
},
"method": "flatrate_flatrate",
"total": {
"base_shipping_amount": 0,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 0,
"base_shipping_invoiced": 0,
"base_shipping_tax_amount": 0,
"shipping_amount": 0,
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 0,
"shipping_invoiced": 0,
"shipping_tax_amount": 0
}
},
"items": [
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_original_price": 100,
"base_price": 100,
"base_price_incl_tax": 100,
"base_row_invoiced": 200,
"base_row_total": 200,
"base_row_total_incl_tax": 200,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2022-01-13 06:46:19",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 144,
"name": "Accessories monogram D",
"no_discount": 0,
"order_id": 99,
"original_price": 100,
"price": 100,
"price_incl_tax": 100,
"product_id": 17,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 2,
"qty_ordered": 2,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 568,
"row_invoiced": 200,
"row_total": 200,
"row_total_incl_tax": 200,
"row_weight": 200,
"sku": "Accessories monogram D",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2022-01-13 06:46:19",
"weee_tax_applied": "[]",
"weight": 100
}
]
}
],
"payment_additional_info": [
{
"key": "paypal_express_checkout_shipping_overridden",
"value": "0"
},
{
"key": "button",
"value": "1"
},
{
"key": "paypal_express_checkout_shipping_method",
"value": ""
},
{
"key": "paypal_payer_id",
"value": "TUZYUGM3ERY3Q"
},
{
"key": "paypal_payer_email",
"value": "cs.hemantsingh@gmail.com"
},
{
"key": "paypal_payer_status",
"value": "unverified"
},
{
"key": "paypal_address_status",
"value": "confirmed"
},
{
"key": "paypal_correlation_id",
"value": "133ea25fc4520"
},
{
"key": "paypal_express_checkout_payer_id",
"value": "TUZYUGM3ERY3Q"
},
{
"key": "paypal_express_checkout_token",
"value": "EC-98T36492VK521913U"
},
{
"key": "method_title",
"value": "PayPal Express Checkout"
},
{
"key": "paypal_express_checkout_redirect_required",
"value": "null"
},
{
"key": "paypal_protection_eligibility",
"value": "Eligible"
},
{
"key": "paypal_payment_status",
"value": "completed"
},
{
"key": "paypal_pending_reason",
"value": "None"
}
],
"applied_taxes": [],
"item_applied_taxes": []
}
}

 

Conclusion:

If you want to get order information of customers then you can use the default rest API of Magento 2 for that.

We can get the order details in two ways one is on the basis of email id and the other on the basis of order id.

 

 

Related Posts:

Product Search REST API: List of REST APIs in Magento 2

How to Create REST API in Magento 2, For Beginners Guide