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

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

I am going to show you a step-by-step way to how create custom rest API in Magento 2 store.

Rest API works as Request and Response to perform the certain task in Magento 2.

When we make an application using Magento 2 as a mobile application then we use the request-response concept to receive data or save data.

Magento provides some APIs to you by default you just need to use them.

If you want to change it, you can still change it, but for that, you need to know the basics to customize the core rest api.

In order to create the custom rest API in Magento 2, you can follow the below steps.

Create REST API in Magento 2

 

Step 1: Create REST API Registration File

In the first step of custom rest api we have to create a registration file through which we can register our extension.

Wishusucess/CustomApi/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_CustomApi',
__DIR__
);

 

Step 2: Create Module File

Now in the second step, you have to create a module.xml file of this custom rest api extension so that we can give its basic details like its version, model name, etc.

Wishusucess/CustomApi/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Wishusucess_CustomApi" setup_version="1.0.0" />
</config>

 

Step 3: Create REST API Webapi File

In its third step, first of all, we will decide the route URL, how we want to get the data.

Its endpoint will be this route url which will decide that when we hit this endpoint, we will get the data.

Wishusucess/CustomApi/etc/webapi.xml

In this file of Web API, we also decide that the endpoint will work on the key method.

<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">
<route method="POST" url="/V1/custom/custom-api/">
<service class="Wishusucess\CustomApi\Api\CustomInterface" method="getPost"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>

 

Step 4: Dependency Injection for Custom API

Through this file, we will set the preferences and give its path to this file so that it can recognize the extension when run.

Wishusucess/CustomApi/etc.di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Wishusucess\CustomApi\Api\CustomInterface" type="Wishusucess\CustomApi\Model\Api\Custom"/>
</config>

 

Step 5: Create REST API Custom Interface

This will write the custom interface of the custom API in the file, which will process the data and send it to us as a data response.

Wishusucess/CustomApi/Api/CustomInterface.php
<?php
namespace Wishusucess\CustomApi\Api;
interface CustomInterface
{
/**
* GET for Post api
* @param string $value
* @return string
*/
public function getPost($value);
}

 

Step 6: Custom API Model Class

You have to decide with this file what kind of data you want to take from your application, and how you want to take and show it on the front end.

Wishusucess/CustomApi/Model/Api/Custom.php
<?php
namespace Wishusucess\CustomApi\Model\Api;
use Psr\Log\LoggerInterface;
class Custom
{
protected $logger;
public function __construct(
LoggerInterface $logger
)
{
$this->logger = $logger;
}
/**
* @inheritdoc
*/
public function getPost($value)
{
$response = ['success' => false];
try {
// Your Code here
$response = ['success' => true, 'message' => $value];
} catch (\Exception $e) {
$response = ['success' => false, 'message' => $e->getMessage()];
$this->logger->info($e->getMessage());
}
$returnArray = json_encode($response);
return $returnArray; 
}
}

 

Read more: How To Create Blogging Website at Cheap Price in 2022

 

Step 7: Check Custom API with Postman

We will test the custom rest API that we have created above using the postman free tool.

The method which we have mentioned in the file will be selected in this postman's method option.

We will give the endpoint which we have defined in the web api's route url, in the url option.

Now we will hit the endpoint then we will see some data like the below screen in the form of a response.

 

 

Similar Posts:

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

Quick and Advanced Search Container REST API Magento 2

Search REST API List: Magento 2 API List of Product Search Endpoint

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

I am sharing below a list of the product search rest API of how to filter and search any product inside Magento 2.

With the help of this, you will be able to access all the lists of APIs on a single platform.

Within this, you can also search for the product on the basis of the ID of any category.

Whether it is to do an advanced search, you can search and filter the product using the API by all means.

You can also search products on the basis of price i.e. from low price to max price.

You can search the product by product name.

Search by ID using rest API also available in this list.

 

Product Search REST API for Search And Filter

There are many ways to filter a product in Magento, one of them is you can filter a product is by category ID.

So using this REST API, you can field all products of any category ID.

Or if you want to filter the product by category name then you can also use this rest API in Magento 2.

Endpoint:

https://wishusucess.com/rest/V1/categories/2/products

Method: GET

Header:

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

Example:

Filter Product By Category ID

Response:

[
{
"sku": "24-MB01",
"position": 0,
"category_id": "2"
},
{
"sku": "24-MB04",
"position": 0,
"category_id": "2"
},
{
"sku": "WSH12",
"position": 0,
"category_id": "2"
}
]

 

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

 

Quick Searches REST API in Magento 2

Below is the Quick search container Magento 2 REST API that will help you to search the product quickly.

Endpoint:

https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filter_groups][0][filters][0][field]=search_term&searchCriteria[filter_groups][0][filters][0][value]=iphone

Method: GET

Header:

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

Example:

Quick Search REST API Magento

Read more: Search Container REST API

 

Advanced Search Container Magento 2 REST API

Advanced_search_container

Endpoint

https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=advanced_search_container&searchCriteria[filter_groups][0][filters][0][field]=price.from&searchCriteria[filter_groups][0][filters][0][value]=200&searchCriteria[filter_groups][0][filters][1][field]=price.to&searchCriteria[filter_groups][0][filters][1][value]=500

Method: GET

Header:

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

Example:

Advanced Search Container REST API

Response:

{
"items": [],
"aggregations": {
"buckets": [],
"bucket_names": []
},
"search_criteria": {
"request_name": "advanced_search_container",
"filter_groups": [
{
"filters": [
{
"field": "price.from",
"value": "200",
"condition_type": "eq"
},
{
"field": "price.to",
"value": "500",
"condition_type": "eq"
}
]
}
]
},
"total_count": 0
}

Read more: Search Container REST API

 

Gets Products Where The SKU Search in Magento 2 REST API

Looking for API to search catalog product inside magento2 rising rest API then you can use below endpoint.

This API is used to perform product searches based on SKU inside the magento2 store.

In order to do an SKU-based products search, you have to hit the below Magento 2 rest API endpoint, after hitting it, whatever content matches it, you will get it as a response.

Endpoint

https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=advanced_search_container&searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=24-MB01&searchCriteria[filter_groups][0][filters][0][condition_type]=like

Method: GET

Header:

  • Authorization: Bearer <admin_token>
  • Contnet Type: application/json

Example:

Product With SKU Search REST API

Response:

{
"items": [
{
"id": 1,
"custom_attributes": [
{
"attribute_code": "score",
"value": "0.0000000000000000"
}
]
}
],
"aggregations": {
"buckets": [],
"bucket_names": []
},
"search_criteria": {
"request_name": "advanced_search_container",
"filter_groups": [
{
"filters": [
{
"field": "sku",
"value": "24-MB01",
"condition_type": "like"
}
]
}
]
},
"total_count": 1
}

 

Product Filter Using Price And SKU in Magento 2 REST API

To search catalog product inside Magento 2 store if we want to add some condition like catalog product search based on SKU and price range both together.

So for that Magento 2 has a separate rest API endpoint we have to hit that endpoint.

And also we can decide the price range according to our need and SKU add both have to be added together as add param.

Endpoint:

https://wishusucess.com/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Coquefhoih72389&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=sku&searchCriteria[filter_groups][0][filters][1][value]=Coque12345&searchCriteria[filter_groups][0][filters][1][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=400&searchCriteria[filter_groups][1][filters][0][condition_type]=from&searchCriteria[filter_groups][2][filters][0][field]=price&searchCriteria[filter_groups][2][filters][0][value]=600&searchCriteria[filter_groups][2][filters][0][condition_type]=to

Method: GET

Header:

  • Authorization: Bearer <admin_token>
  • Contnet Type: application/json

Example:

Product Filter Using Price and SKU REST API

Response:

{
"items": [],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "sku",
"value": "Coquefhoih72389",
"condition_type": "like"
},
{
"field": "sku",
"value": "Coque12345",
"condition_type": "like"
}
]
},
{
"filters": [
{
"field": "price",
"value": "400",
"condition_type": "from"
}
]
},
{
"filters": [
{
"field": "price",
"value": "600",
"condition_type": "to"
}
]
}
]
},
"total_count": 0
}

 

 

A Simple Search Using an in Conditions Type

For logical OR search, one has to hit logical OR search rest API in Magento website i.e. inside normal condition search rest API we will add any product name or whatever you want to search string as a string.

Then after that when you hit the endpoint then the response you get after that will be the response of your conditional search reply.

Endpoint:

https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=name&searchCriteria[filter_groups][0][filters][0][value]=Coque Carbone et Effet Brossé Silicone à Coins Renforcés&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=name&searchCriteria[filter_groups][0][filters][1][value]=Accessoires Apple iPhone&searchCriteria[filter_groups][0][filters][1][condition_type]=like

Method: GET

Header:

  • Authorization: Bearer <admin_token>
  • Contnet Type: application/json

Example:

Magento 2 Simple Search Using Condition REST API

 

 

Response:

{
"items": [],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "name",
"value": "Coque Carbone et Effet Brossé Silicone à Coins Renforcés",
"condition_type": "like"
},
{
"field": "name",
"value": "Accessoires Bag",
"condition_type": "like"
}
]
}
]
},
"total_count": 0
}

 

Logical and Condition Search REST API Magento 2

For logical and conditional search we have to hit REST API of the Magento 2 website.

Whatever condition we have to send in this, we can decide and we can impose the logical conditions.

As its key value, we can add both SKU and Price together, and as soon as hit we will get the data as a response.

Endpoint:

https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Accessoires1278&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=2500&searchCriteria[filter_groups][1][filters][0][condition_type]=lt

Method: GET

Header:

  • Authorization: Bearer <admin_token>
  • Contnet Type: application/json

Example:

Logical and Condition Search API

Response:

{
"items": [],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "sku",
"value": "MS",
"condition_type": "like"
}
]
},
{
"filters": [
{
"field": "price",
"value": "2500",
"condition_type": "lt"
}
]
}
]
},
"total_count": 0
}

 

 

Magento 2 Logical AND and OR Search REST API

In this logical and conditional search, you have to send SKU along with price range can also apply like a price from to price to price.

All the products available in this range in between, you will get the data in the form of a response.

Endpoint:

https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Accessoires1278&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=sku&searchCriteria[filter_groups][0][filters][1][value]=Coquefhoih72389&searchCriteria[filter_groups][0][filters][1][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=200&searchCriteria[filter_groups][1][filters][0][condition_type]=from&searchCriteria[filter_groups][2][filters][0][field]=price&searchCriteria[filter_groups][2][filters][0][value]=600&searchCriteria[filter_groups][2][filters][0][condition_type]=to

Method: GET

Header:

  • Authorization: Bearer <admin_token>
  • Contnet Type: application/json

Example:

Logical and Condition Search With Price and SKU

Response:

{
"items": [
{
"id": 1,
"sku": "24-MB01",
"name": "Joust Duffle Bag",
"attribute_set_id": 15,
"price": 34,
"status": 1,
"visibility": 4,
"type_id": "simple",
"created_at": "2022-01-24 18:19:43",
"updated_at": "2022-01-24 18:19:43",
"extension_attributes": {
"website_ids": [
1
],
"category_links": [
{
"position": 0,
"category_id": "3"
},
{
"position": 0,
"category_id": "4"
}
]
},
"product_links": [
{
"sku": "24-MB01",
"link_type": "crosssell",
"linked_product_sku": "24-UG01",
"linked_product_type": "simple",
"position": 3
},
{
"sku": "24-MB01",
"link_type": "crosssell",
"linked_product_sku": "24-WG083-blue",
"linked_product_type": "simple",
"position": 2
},
{
"sku": "24-MB01",
"link_type": "crosssell",
"linked_product_sku": "24-WG086",
"linked_product_type": "simple",
"position": 1
},
{
"sku": "24-MB01",
"link_type": "crosssell",
"linked_product_sku": "24-WG085_Group",
"linked_product_type": "grouped",
"position": 4
},
{
"sku": "24-MB01",
"link_type": "upsell",
"linked_product_sku": "24-MB03",
"linked_product_type": "simple",
"position": 2
},
{
"sku": "24-MB01",
"link_type": "upsell",
"linked_product_sku": "24-MB05",
"linked_product_type": "simple",
"position": 3
},
{
"sku": "24-MB01",
"link_type": "upsell",
"linked_product_sku": "24-MB06",
"linked_product_type": "simple",
"position": 4
},
{
"sku": "24-MB01",
"link_type": "upsell",
"linked_product_sku": "24-MB02",
"linked_product_type": "simple",
"position": 1
},
{
"sku": "24-MB01",
"link_type": "upsell",
"linked_product_sku": "24-UB02",
"linked_product_type": "simple",
"position": 5
},
{
"sku": "24-MB01",
"link_type": "upsell",
"linked_product_sku": "24-WB03",
"linked_product_type": "simple",
"position": 6
},
{
"sku": "24-MB01",
"link_type": "upsell",
"linked_product_sku": "24-WB07",
"linked_product_type": "simple",
"position": 8
},
{
"sku": "24-MB01",
"link_type": "upsell",
"linked_product_sku": "24-WB04",
"linked_product_type": "simple",
"position": 7
}
],
"options": [],
"media_gallery_entries": [
{
"id": 1,
"media_type": "image",
"label": "Image",
"position": 1,
"disabled": false,
"types": [
"image",
"small_image",
"thumbnail"
],
"file": "/m/b/mb01-blue-0.jpg"
}
],
"tier_prices": [],
"custom_attributes": [
{
"attribute_code": "image",
"value": "/m/b/mb01-blue-0.jpg"
},
{
"attribute_code": "small_image",
"value": "/m/b/mb01-blue-0.jpg"
},
{
"attribute_code": "thumbnail",
"value": "/m/b/mb01-blue-0.jpg"
},
{
"attribute_code": "url_key",
"value": "joust-duffle-bag"
},
{
"attribute_code": "required_options",
"value": "0"
},
{
"attribute_code": "has_options",
"value": "0"
},
{
"attribute_code": "category_ids",
"value": [
"3",
"4"
]
},
{
"attribute_code": "description",
"value": "<p>The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.<p>\n<ul>\n<li>Dual top handles.</li>\n<li>Adjustable shoulder strap.</li>\n<li>Full-length zipper.</li>\n<li>L 29\" x W 13\" x H 11\".</li>\n</ul>"
}
]
}
],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "sku",
"value": "Accessoires1278",
"condition_type": "like"
},
{
"field": "sku",
"value": "24-MB01",
"condition_type": "like"
}
]
},
{
"filters": [
{
"field": "price",
"value": "30",
"condition_type": "from"
}
]
},
{
"filters": [
{
"field": "price",
"value": "600",
"condition_type": "to"
}
]
}
]
},
"total_count": 1
}

 

You can get all types of search data on the Magento website by changing a little bit in this way.

Now be it price filter, category search, product name search, all types of data can be accessed using this REST API in Magento 2.

Now despite this, if you need any help, then you can contact us, we will try our best to help you.

Thank you!!

Quick and Advanced Search Container REST API Magento 2

Product search is a very critical part of any e-commerce website. When the customer needs a specific product, he searches in this quick and advanced search bar itself.

There are two REST APIs inside Magento, one for quick search and one for advanced search.

Under Quick Search, the customer enters a particular name or SKU, ie, enters the search term.

And then after that, it hits and as soon as there is a matching product with that particular name, we will get that product as a response.

If the customer wants the product to be visible in the middle of a particular range, then for that we have to use the advanced search container which is given below endpoint.

 

Magento 2 Quick and Advanced Search REST API

Two search containers are given below of Magento 2 Quick and Advanced Search REST API.

 

Quick Searches REST API in Magento 2

When we open the Magento 2 website, the normal product catalog search that appears is called the quick search container.

If we want to get the data of that quick search container through Rest API in Magento 2, then for that I am mentioning the endpoints below.

You can get the data by adding content-type application JSON and method entering the authorized bearer token in the header.

Endpoint:

https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filter_groups][0][filters][0][field]=search_term&searchCriteria[filter_groups][0][filters][0][value]=iphone

Method: GET

Header:

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

Example:Quick Search Container PRAM API

Response:

{
"items": [
{
"id": 14,
"custom_attributes": [
{
"attribute_code": "score",
"value": "116.2562599182128900"
}
]
},
{
"id": 8,
"custom_attributes": [
{
"attribute_code": "score",
"value": "116.2562599182128900"
}
]
},
{
"id": 4,
"custom_attributes": [
{
"attribute_code": "score",
"value": "116.2562599182128900"
}
]
},
{
"id": 1,
"custom_attributes": [
{
"attribute_code": "score",
"value": "116.2562599182128900"
}
]
},
{
"id": 2046,
"custom_attributes": [
{
"attribute_code": "score",
"value": "103.3388977050781200"
}
]
},
{
"id": 1722,
"custom_attributes": [
{
"attribute_code": "score",
"value": "103.3388977050781200"
}
]
},
{
"id": 688,
"custom_attributes": [
{
"attribute_code": "score",
"value": "38.7520866394043000"
}
]
},
{
"id": 23,
"custom_attributes": [
{
"attribute_code": "score",
"value": "6.4586811065673830"
}
]
},
{
"id": 15,
"custom_attributes": [
{
"attribute_code": "score",
"value": "6.4586811065673830"
}
]
},
{
"id": 3,
"custom_attributes": [
{
"attribute_code": "score",
"value": "6.4586811065673830"
}
]
}
],
"aggregations": {
"buckets": [
{
"name": "category_bucket",
"values": [
{
"value": "3",
"metrics": [
"3",
"7"
]
},
{
"value": "4",
"metrics": [
"4",
"5"
]
},
{
"value": "5",
"metrics": [
"5",
"2"
]
},
{
"value": "7",
"metrics": [
"7",
"2"
]
},
{
"value": "8",
"metrics": [
"8",
"2"
]
},
{
"value": "12",
"metrics": [
"12",
"1"
]
},
{
"value": "17",
"metrics": [
"17",
"1"
]
},
{
"value": "21",
"metrics": [
"21",
"1"
]
},
{
"value": "22",
"metrics": [
"22",
"1"
]
},
{
"value": "26",
"metrics": [
"26",
"1"
]
},
{
"value": "28",
"metrics": [
"28",
"1"
]
},
{
"value": "34",
"metrics": [
"34",
"2"
]
}
]
}
],
"bucket_names": [
"category_bucket"
]
},
"search_criteria": {
"request_name": "quick_search_container",
"filter_groups": [
{
"filters": [
{
"field": "search_term",
"value": "bag",
"condition_type": "eq"
}
]
}
]
},
"total_count": 10
}

 

 

Product Advanced Search Container REST API

By using this advanced search container REST API, you can do an advanced search of the product of the Magento store.

You can set the minimum price and set a maximum price.

Whatever product is in between the minimum price to the maximum price, you will see it as a response.

For example, if you have set the minimum price as 200 and the maximum price is 500, then all the products in the range between 200 to 500 will be shown to you as a response through this rest API

Endpoint

https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=advanced_search_container&searchCriteria[filter_groups][0][filters][0][field]=price.from&searchCriteria[filter_groups][0][filters][0][value]=200&searchCriteria[filter_groups][0][filters][1][field]=price.to&searchCriteria[filter_groups][0][filters][1][value]=500

Method: GET

Header:

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

Body: Not required

Advanced Search Container REST API

 

Advanced Search Container PRAM in REST API

Advanced Search Container PRAM in API

 

Response:

{
"items": [],
"aggregations": {
"buckets": [],
"bucket_names": []
},
"search_criteria": {
"request_name": "advanced_search_container",
"filter_groups": [
{
"filters": [
{
"field": "price.from",
"value": "200",
"condition_type": "eq"
},
{
"field": "price.to",
"value": "500",
"condition_type": "eq"
}
]
}
]
},
"total_count": 0
}

 

Read more: Search REST API List: Magento 2 API List of Product Search Endpoint

How To Create Blogging Website at Cheap Price in 2022

Search REST API List: Magento 2 API List of Product Search Endpoint

Here I am giving you a complete list of all the search REST API list or product filtering REST APIs inside Magento 2.

This will give you easy access to the API collection in one place.

Search REST API in Magento 2

You can easily do this list of APIs together and when you create a mobile application, it will be very convenient to filter any kind of data.

Within this API list, you will find all the details of how to filter any product by category ID or search, how to remove the collection, in the list given below.

If you want information in detail, then by clicking on the related link given below, you can go to another page, where its complete detail with example is given.

 

Magento 2 List of All Search REST API

When you will go to another page by clicking on that link, there you have to use what methods, which token to use in authorization, what should be the body content type you will get.

1. Product Search REST API for Search And Filter

https://wishusucess.com/rest/V1/categories/115/products

2. Quick Searches REST API in Magento 2

https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filter_groups][0][filters][0][field]=search_term&searchCriteria[filter_groups][0][filters][0][value]=iphone

3. Advanced Search Container Magento 2 REST API

https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=advanced_search_container&searchCriteria[filter_groups][0][filters][0][field]=price.from&searchCriteria[filter_groups][0][filters][0][value]=200&searchCriteria[filter_groups][0][filters][1][field]=price.to&searchCriteria[filter_groups][0][filters][1][value]=500

4. Gets Products Where The SKU Search in Magento 2 REST API

https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=advanced_search_container&searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Accessoires1278&searchCriteria[filter_groups][0][filters][0][condition_type]=like

5. Product Filter Using Price And SKU in Magento 2 REST API

https://wishusucess.com/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Coquefhoih72389&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=sku&searchCriteria[filter_groups][0][filters][1][value]=Coque12345&searchCriteria[filter_groups][0][filters][1][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=400&searchCriteria[filter_groups][1][filters][0][condition_type]=from&searchCriteria[filter_groups][2][filters][0][field]=price&searchCriteria[filter_groups][2][filters][0][value]=600&searchCriteria[filter_groups][2][filters][0][condition_type]=to

6. A Simple Search Using an in Conditions Type

https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=name&searchCriteria[filter_groups][0][filters][0][value]=Coque Carbone et Effet Brossé Silicone à Coins Renforcés&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=name&searchCriteria[filter_groups][0][filters][1][value]=Accessoires Apple iPhone&searchCriteria[filter_groups][0][filters][1][condition_type]=like

7. Logical and Condition Search REST API Magento 2

https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Accessoires1278&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=2500&searchCriteria[filter_groups][1][filters][0][condition_type]=lt

8. Magento 2 Logical AND and OR Search REST API

https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Accessoires1278&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=sku&searchCriteria[filter_groups][0][filters][1][value]=Coquefhoih72389&searchCriteria[filter_groups][0][filters][1][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=200&searchCriteria[filter_groups][1][filters][0][condition_type]=from&searchCriteria[filter_groups][2][filters][0][field]=price&searchCriteria[filter_groups][2][filters][0][value]=600&searchCriteria[filter_groups][2][filters][0][condition_type]=to

 

If you need any kind of help in Magento 2 store development then you can mail or message us or call us immediately, we will try our best to help you in every way from development.

If any query is also related to mobile application development or creating a store using the Magento framework and facing any problem, you can take help from us.

 

Recommended Posts:

Magento 2.4 Installation Guide: How to Install Magento 2.4.2

Magento Store: Best 36 Magento Website Examples in The World

Get Category Page Detail Using Category Page REST API

While creating a mobile application we need to get the data of the list page through the Magento 2 category page rest API.

In this sequence, I am telling you the steps here, using which you can get the information of the category page through Magento 2 API.

If you are searching Magento 2 REST API to get all categories where the is_active attribute is true in that case also you can use the below api.

You can also get the data of the enabled category of any store through the default REST API of Magento 2 given below

This Magento API behaves in such a way that you can get only the data of the active category, then you can use this API.

If a category is disabled, its attribute will not be active

 

Category Collection REST API Magento 2

This Magento 2 REST api of the category page lets you get category collection through store view code.

Through this, you can get the collection of entire store category collection details.

Endpoint:

https://www.wishusucess.com/rest/default/V1/categories

Method: GET

Header

  • Content-type: application/json
  • Authorization: Bearer Admin Token

Authorization: Not required

Category Page REST API in Magento 2

 

Response:

{
"id": 2,
"parent_id": 1,
"name": "Default Category",
"is_active": true,
"position": 1,
"level": 1,
"product_count": 1181,
"children_data": [
{
"id": 38,
"parent_id": 2,
"name": "What's New",
"is_active": true,
"position": 1,
"level": 2,
"product_count": 0,
"children_data": []
},


{
"id": 29,
"parent_id": 2,
"name": "Promotions",
"is_active": false,
"position": 6,
"level": 2,
"product_count": 0,
"children_data": [
{
"id": 30,
"parent_id": 29,
"name": "Women Sale",
"is_active": true,
"position": 1,
"level": 3,
"product_count": 224,
"children_data": []
},
{
"id": 31,
"parent_id": 29,
"name": "Men Sale",
"is_active": true,
"position": 2,
"level": 3,
"product_count": 39,
"children_data": []
},
{
"id": 32,
"parent_id": 29,
"name": "Pants",
"is_active": true,
"position": 3,
"level": 3,
"product_count": 247,
"children_data": []
},
{
"id": 33,
"parent_id": 29,
"name": "Tees",
"is_active": true,
"position": 4,
"level": 3,
"product_count": 192,
"children_data": []
}
]
},
{
"id": 37,
"parent_id": 2,
"name": "Sale",
"is_active": true,
"position": 6,
"level": 2,
"product_count": 0,
"children_data": []
}
]
}

 

Read more: Get Product Image URL Via Magento 2 REST API

 

Get All Category Page Data Via API in Magento 2

There is not much difference between the first and this API, but through this API you can get the complete category data of any Magento  2 website.

Using this REST API of Magento, you can easily get any categories and their subcategories across the store

Endpoint:

https://www.wishusucess.com/index.php/rest/V1/categories/

Method: GET

Header

  • Content-type: application/json
  • Authorization: Bearer Admin Token

Authorization: Not required

Category Collection REST API

 

Response:

{
"id": 2,
"parent_id": 1,
"name": "Default Category",
"is_active": true,
"position": 1,
"level": 1,
"product_count": 1181,
"children_data": [
{
"id": 38,
"parent_id": 2,
"name": "What's New",
"is_active": true,
"position": 1,
"level": 2,
"product_count": 0,
"children_data": []
},
{
"id": 29,
"parent_id": 2,
"name": "Promotions",
"is_active": false,
"position": 6,
"level": 2,
"product_count": 0,
"children_data": [
{
"id": 30,
"parent_id": 29,
"name": "Women Sale",
"is_active": true,
"position": 1,
"level": 3,
"product_count": 224,
"children_data": []
},
{
"id": 31,
"parent_id": 29,
"name": "Men Sale",
"is_active": true,
"position": 2,
"level": 3,
"product_count": 39,
"children_data": []
},
{
"id": 32,
"parent_id": 29,
"name": "Pants",
"is_active": true,
"position": 3,
"level": 3,
"product_count": 247,
"children_data": []
},
{
"id": 33,
"parent_id": 29,
"name": "Tees",
"is_active": true,
"position": 4,
"level": 3,
"product_count": 192,
"children_data": []
}
]
},
{
"id": 37,
"parent_id": 2,
"name": "Sale",
"is_active": true,
"position": 6,
"level": 2,
"product_count": 0,
"children_data": []
}
]
}

 

 

REST API for All Category Details With Image File

In this API, you can also get the image URL of each category simultaneously.

Rest of the details will remain the same as before API.

Magento 2 API, with the help of which all the category data of any store along with the image of each category is also available

Endpoint:

https://wishusucess.com/index.php/rest/V1/categories/list?searchCriteria[filterGroups][0][filters][0][field]=parent_id&searchCriteria[filterGroups][0][filters][0][value]=2

Method: GET

Header

  • Content-type: application/json
  • Authorization: Bearer Admin Token

Authorization: Not required

All Category Details Using Image File

 

Response

{
"items": [
{
"id": 3,
"parent_id": 2,
"name": "Gear",
"is_active": true,
"position": 4,
"level": 2,
"children": "4,5,6",
"created_at": "2022-01-20 14:12:16",
"updated_at": "2022-01-20 14:12:17",
"path": "1/2/3",
"available_sort_by": [],
"include_in_menu": true,
"custom_attributes": [
{
"attribute_code": "display_mode",
"value": "PAGE"
},
{
"attribute_code": "is_anchor",
"value": "0"
},
{
"attribute_code": "path",
"value": "1/2/3"
},
{
"attribute_code": "children_count",
"value": "3"
},
{
"attribute_code": "url_key",
"value": "gear"
},
{
"attribute_code": "url_path",
"value": "gear"
}
]
},
{
"id": 37,
"parent_id": 2,
"name": "Sale",
"is_active": true,
"position": 6,
"level": 2,
"children": "",
"created_at": "2022-01-20 14:15:55",
"updated_at": "2022-01-20 14:15:55",
"path": "1/2/37",
"available_sort_by": [],
"include_in_menu": true,
"custom_attributes": [
{
"attribute_code": "display_mode",
"value": "PAGE"
},
{
"attribute_code": "is_anchor",
"value": "0"
},
{
"attribute_code": "path",
"value": "1/2/37"
},
{
"attribute_code": "children_count",
"value": "0"
},
{
"attribute_code": "url_key",
"value": "sale"
},
{
"attribute_code": "url_path",
"value": "sale"
}
]
},
{
"id": 38,
"parent_id": 2,
"name": "What's New",
"is_active": true,
"position": 1,
"level": 2,
"children": "",
"created_at": "2022-01-20 14:15:55",
"updated_at": "2022-01-20 14:15:55",
"path": "1/2/38",
"available_sort_by": [],
"include_in_menu": true,
"custom_attributes": [
{
"attribute_code": "display_mode",
"value": "PAGE"
},
{
"attribute_code": "is_anchor",
"value": "0"
},
{
"attribute_code": "path",
"value": "1/2/38"
},
{
"attribute_code": "children_count",
"value": "0"
},
{
"attribute_code": "url_key",
"value": "what-is-new"
},
{
"attribute_code": "url_path",
"value": "what-is-new"
}
]
}
],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "parent_id",
"value": "2",
"condition_type": "eq"
}
]
}
]
},
"total_count": 3
}

 

Similar Posts:

How to Get New Arrival Product REST API in Magento 2

Create Account REST API : How to Create an Account of Customer, Admin

 

Suggested Post:

BMLT Course in Hindi: Scope and Future Career in BMLT, Eligibility

How to Get New Arrival Product REST API in Magento 2

In this article, we will learn how to filter the products of a Magento 2 store using the REST API and we will also know how to get new arrival products REST API.

By the way, Magento 2 Provides a facility for the REST API that is well known as Swagger Module which contains all list of REST APIs resources:

Using this model, you can get the product by visualizing and testing it through REST API.

When you hit the URL of your store by typing swagger you will get the list details of all the APIs.

Like I have taken an example below, according to this example you enter your URL and hit it, then you will get the API.

Endpoint:

http://www.wishusucess.com/swagger

Here we are filtering the product on the basis of attribute and the name of that attribute is a new product.

So while filtering the product through Rest API, we will get the newly added product by filtering

 

 

Get New Arrival Products REST API

 

To filter a new product, what should be its search criteria and which method will be used, what access token will be used, the details of all these are given below.

Endpoint

https://www.wishusucess.com/rest/V1/products?searchCriteria[sortOrders][0][field]=created_at&searchCriteria[pageSize]=10

Method: GET

Header: 

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

Body: none

New Arrival Products REST API

Search Parameter for New Arrivals in REST API

 

Created At New Arrivals

Response:

{
"items": [
{
"id": 2007,
"sku": "WSH08-31-Purple",
"name": "Sybil Running Short-31-Purple",
"attribute_set_id": 10,
"price": 44,
"status": 1,
"visibility": 1,
"type_id": "simple",
"created_at": "2021-12-23 09:40:40",
"updated_at": "2021-12-23 09:40:40",
"weight": 1,
"extension_attributes": {
"website_ids": [
1
],
"category_links": [
{
"position": 0,
"category_id": "28"
},
{
"position": 0,
"category_id": "35"
},
{
"position": 0,
"category_id": "2"
}
]
},
"product_links": [],
"options": [],
"media_gallery_entries": [
{
"id": 3353,
"media_type": "image",
"label": "",
"position": 1,
"disabled": false,
"types": [
"image",
"small_image",
"thumbnail"
],
"file": "/w/s/wsh08-purple_main_1.jpg"
},
{
"id": 3354,
"media_type": "image",
"label": "",
"position": 2,
"disabled": false,
"types": [],
"file": "/w/s/wsh08-purple_back_1.jpg"
}
],
"tier_prices": [],
"custom_attributes": [
{
"attribute_code": "image",
"value": "/w/s/wsh08-purple_main_1.jpg"
},
{
"attribute_code": "small_image",
"value": "/w/s/wsh08-purple_main_1.jpg"
},
{
"attribute_code": "thumbnail",
"value": "/w/s/wsh08-purple_main_1.jpg"
},
{
"attribute_code": "options_container",
"value": "container2"
},
{
"attribute_code": "msrp_display_actual_price_type",
"value": "0"
},
{
"attribute_code": "url_key",
"value": "sybil-running-short-31-purple"
},
{
"attribute_code": "required_options",
"value": "0"
},
{
"attribute_code": "has_options",
"value": "0"
},
{
"attribute_code": "tax_class_id",
"value": "2"
},
{
"attribute_code": "category_ids",
"value": [
"28",
"35",
"2"
]
},
{
"attribute_code": "description",
"value": "<p>Fortunately, it's okay to look cute while you're working out. The Sybil Running Short combines a fun, color-blocked design with breathable mesh fabric for sporty-fun style.</p>\n<p>&bull; Blue running shorts with green waist.<br />&bull; Drawstring-adjustable waist.<br />&bull; 4\" inseam. Machine wash/line dry.</p>"
},
{
"attribute_code": "size",
"value": "174"
},
{
"attribute_code": "color",
"value": "57"
}
]
}
],
"search_criteria": {
"filter_groups": [],
"sort_orders": [
{
"field": "created_at",
"direction": null
}
],
"page_size": 1
},
"total_count": 2046
}

 

Similar Posts:

Create Account REST API : How to Create an Account of Customer, Admin

Magento 2 Login REST API: How to Login Customer, Admin

Wishusucess on GitHub

Create Account REST API : How to Create an Account of Customer, Admin

In this article, I am going to explain to you how to use create account rest api in Magento 2. In this, I will also explain to you how to create customer and admin accounts using REST API.

Whenever you order a product inside the Magento store, there are three ways to do it.

By creating a customer account, we can order the product, which we call registered users or they are also called logged-in customers.

Another way is that customers can order products without registering an account, whom we know as guest users.

The third way is that the guest customer is registered only at the time of ordering.

As a guest user who logs in or creates an account when ordering
Through this article, I am going to explain how to register a client through the REST endpoint.

 

 

Admin Create Account REST API

Now if you are looking for the REST API endpoint to create Magento 2 admin users s you can follow the below steps.

 

Endpoint:

The below details are the basic structure of REST APIs to call in Magento 2.

<HTTP verb> http://<host>/rest/<scope>/<endpoint>

HTTP headers:

Through this section, we send the required authentication details and tell the Magento store that we are the authentic user who can access the requested data.

Payload:

Through this section, we send necessary valid details along with the endpoint.

POST <host>/rest/<store_code>/V1/tfa/provider/google/authenticate
{
"username": "admin",
"password": "<admin-password>",
"otp": "<otp-value>"
}

There is no API to create a Magento admin user you can get the access token of the admin user by using the rest API.

But you can create an admin account from the Magento 2 store in the admin.

Admin Panel > System > Permissions > All User > New User.

 

Response:

When you use the Magento admin rest API to get the access token that returns the admin’s access token in the following format.

4r2jdjdr11j6gmau8990hcj6qk5unh3i

Now, whenever you need to access the backend details or any other details then you have to use this token in the header for the authorization in every call and that header token validate then allows you to access the store details.

 

 

Customer REST API to Create Account

 

To create a customer, we can send all the details in the payload, in the first step I have only added four fields to create a customer in a short way.

But when you create a customer through rest API, all the other fields are optional, that's why you don't need to add all the fields in order to create customer accounts. You can create a customer by sending only four details in the payload in the Rest API.

 

Method 1: REST API to Create Customer in Magento 2

Endpoint:

POST <host>/rest/<store_code>/V1/customers
http://www.wishusucess.com/rest/V1/customers

Method: POST

Authorization: Not required

Body: raw: JSON

Headers: Content-Type: application/json

{
"customer": {
"email": "cs.hemantsingh@gmail.com",
"firstname": "Hemant",
"lastname": "Singh"
},
"password": "aaAdm378in@#123"
}

Create Account REST API in Magento 2

 

Response:

{
"id": 4,
"group_id": 1,
"created_at": "2022-01-14 18:38:21",
"updated_at": "2022-01-14 18:38:21",
"created_in": "Default Store View",
"email": "cs.hemantsingh@gmail.com",
"firstname": "Hemant",
"lastname": "Singh",
"store_id": 1,
"website_id": 1,
"addresses": [],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
}
}

 

Method 2: Create Customer REST API

In this step I am adding full customer details in payload else other details will be the same as the first methiod.

create customer rest api in detail

Response:

{
"id": 5,
"group_id": 1,
"default_billing": "3",
"default_shipping": "3",
"created_at": "2022-01-14 19:02:46",
"updated_at": "2022-01-14 19:02:47",
"created_in": "Default Store View",
"email": "cs.hemants@gmail.com",
"firstname": "Hemant",
"lastname": "Singh",
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 3,
"customer_id": 5,
"region": {
"region_code": "UP",
"region": "Uttar Pradesh",
"region_id": 566
},
"region_id": 566,
"country_id": "IN",
"street": [
"Noida"
],
"telephone": "7992293862",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"default_shipping": true,
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
}
}

 

If you log in to your Magento 2 store with any of the username and password details that you have given while creating the account using REST API, then it will log in successfully.

Or if you go to All Customers in the admin of the store, then your new account that has been created will appear.

Now if you want to implement login functionality using Magento rest api then you can use login rest API.

 

Read more: Magento 2 Login REST API: How to Login Customer, Admin

 

Other Post:

PayPal Account: How to Create New PayPal Account, Transfer

Wishusucess on GitHub

Magento 2 Login REST API: How to Login Customer, Admin

I am going to explain the Magento 2 login REST API for mobile applications so by using those REST APIs you can develop the application using the Magento 2 e-commerce framework.

So these APIs are basically used for the login system for the customers and admin users. You can take help of these proper rest ways to implement the login functionality.

 

 

Magento 2 Login REST API

 

To access the data of any store of your magento, first of all, you have to define yourself that you are the genuine person accessing that data.

Authentication means you have to prove as a genuine user of customer it admin that allows Magento e-commerce store to identify the access rights. It means you have the right to access (administrator, integration, client, or guest) resources of the API call.

Now if you just want to check some things as a front-end customer then you have to log in customer and for that, you have to get a customer access token.

But if you want to access internal details of the store then for that you must have to authenticate your identity and get an access token of admin details.

 

 

Magento 2 Login Rest API Customer

 

Step 1: You must have a customer account in order to get access tokens of customers. If you don't have a user account then you can create a customer account first.

Step 2: Now you have to send the customer user details like username and password in the payload with the POST method.

Step 3: Get customer access token in response.

 

API URL: {baseurl}/rest/V1/integration/customer/token

Endpoint:

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

Method: POST

Authorization: Not required

Body:

{
   "username":"cs.hemantsingh@gmail.com",
   "password":"Admin@#44123"
}

Magento 2 Login REST API

Response:

l2l6ccj0hwvm6pvj7uy7oflr7k7uvabv

 

 

Admin Login REST API in Magento 2

 

If any mobile application is developed using Magento eCommerce then at that time we need to login to Magento admin through rest API.

Let us know what is the complete step of admin login via REST API, by following which we can get this access token.

Step 1: You need a Magento store admin account in order to get access tokens of your stores via rest API.

Step 2: Now by hitting the below details you can get the admin access token. Along with the rest API URL you have to send the admin username and password in the payload with the POST method.

Step 3: Get admin access token in response.

 

API URL: {baseurl}/rest/V1/integration/admin/token

Endpoint: 

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

Method: POST

Header: Not required

Body:

{
    "username":"admin32",
    "password":"Admin555@#123"
}

Magento 2 Login REST API

Response:

9nnv93lsivrfvzyzt1cgdw8f3xnij05v

 

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

 

Similar Post:

How to Make Payment Using PayPal REST API in Magento 2

Configure PayPal in Magento 2 : How to Integrate PayPal

How to Get Catalog Product Images URL Using REST API

When we create a mobile application using Magento 2 eCommerce then we use rest API to get the catalog product image URL.

This post will give you an idea about how you can get the product image and product URL from the REST API in Magento 2.

As we know without images we can give a greater user experience to our customers on any e-commerce website. Images give clarity about the product so customers get engaged with stores and sales increase.

 

Get Catalog Product Image REST API

This is a step-by-step code to get the product image URLs in Magento 2 eCommerce store.

This is useful in all kinds of situations like if you are developing a mobile application for your Magento 2 store then you need the product images so in order to show the product image you need to retrieve the image URL.

 

Step 1: Registration of ProductImageApi

first, we have to register our first API by rergistration.php file so we have to create the file in the below location.

Wishusucess/ProductImageApi/registration.php
<?php
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_ProductImageApi',
__DIR__
);

 

Step 2: Create a Module XML file

Wishusucess/ProductImageApi/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Wishusucess_ProductImageApi" setup_version="1.0.2" />
</config>

 

Step 3: Declare Dependency Injection

Wishusucess/ProductImageApi/etc/di.xml
<?xml version="1.0"?>
<!--
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Wishusucess\ProductImageApi\Api\GetProductImage" type="Wishusucess\ProductImageApi\Model\GetProductImageUrl" />
</config>

 

Step 4: Create Web API Route Path

Wishusucess/ProductImageApi/etc/webapi.xml
<?xml version="1.0"?>
<!--
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">
<route url="/V1/getproductimage/:sku" method="GET">
<service class="Wishusucess\ProductImageApi\Api\GetProductImage" method="getProductImageUrl"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>

 

Step 5: Get Catalog Product Image API Model Class

Wishusucess/ProductImageApi/Model/GetProductImageUrl.php

This model class has the actual login, so we have to write the following code in order to get the catalog product image URL.

<?php
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
namespace Wishusucess\ProductImageApi\Model;

use Wishusucess\ProductImageApi\Api\GetProductImage;

class GetProductImageUrl implements GetProductImage {
/**
* @var \Magento\Store\Model\App\Emulation
*/
protected $appEmulation;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @var \Magento\Catalog\Api\ProductRepositoryInterface
*/
protected $productRepository;
/**
* @var \Magento\Catalog\Helper\Image
*/
protected $imageHelper;
/**
* @param \Magento\Store\Model\App\Emulation $appEmulation
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param \Magento\Catalog\Helper\Image $imageHelper
*/
public function __construct(
\Magento\Store\Model\App\Emulation $appEmulation,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
\Magento\Catalog\Helper\Image $imageHelper
) {
$this->appEmulation = $appEmulation;
$this->storeManager = $storeManager;
$this->productRepository = $productRepository;
$this->imageHelper = $imageHelper;
}
public function getProductImageUrl($sku) {
$storeId = $this->storeManager->getStore()->getId();
$product = $this->productRepository->get($sku);
$this->appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);
if (!$product) {
$response = [
[
"code" => '301',
"message" => "SKU " . $productSku . " Not Found On Magento",
],
];
return $response;
} else {
$image_url = $this->imageHelper->init($product, 'product_base_image')->getUrl();
$response = [
[
"product_image_url" => $image_url,
],
];
return $response;
}
$this->appEmulation->stopEnvironmentEmulation();
}
}

 

Step 6: Images URL API Class

Wishusucess/ProductImageApi/Api/GetProductPage.php
<?php
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
namespace Wishusucess\ProductImageApi\Api;
interface GetProductImage {
/**
* @api
* @param string $sku
* @return array
*/
public function getProductImageUrl($sku);
}

 

That's it.

Now, we execute the following command.

php bin/magento s:up
php bin/magento s:s:d -f
php bin/magento c:c

Now you can test your product images rest API on the postman by hitting the web route URL.

Get Catalog Product Images URL

 

Now you can see the above images, here

The method is POST and the route URL path for the rest of API is your store URL address and the method and the product that you want the images path details.

https://www.your_store_url.com/rest/V1/products/sku

or

https://www.your_store_url.com/rest/V1/getproductimage/sku

GitHub Wishusucess

 

Online Help & Support for Magento 2 REST API

If you need any kind of help and support in Magento 2 rest API then you can call me.

I am always available to support you while extension development REST API development or any help related to Magento 2 stores.

I am giving you the helpline details in the below images.

Magento 2 Free Help and Support

 

Similar Post:

Search REST API: How to Find Product in Magento 2 Using REST API

Payment API: How to Make Payment Through REST API in Magento 2