skip to Main Content

I am trying to get the order list using the below url,

GET METHOD - http://magento.local/index.php/rest/V1/orders?searchCriteria
Header: Authorization: Bearer TOKEN(Customer Token)

But its giving the following response,

{
    "message": "Consumer is not authorized to access %resources",
    "parameters": {
        "resources": "Magento_Sales::sales"
    }
}

what needs to be done to get the order list using customer token?

3

Answers


  1. Unfortunately it’s not implemented in Magento_Sales::sales yet, but you can extend your own API. follow the following issue:
    https://github.com/magento/magento2/issues/3552

    Login or Signup to reply.
  2. For the get Customer Order history use searchCriteria and passed customer_email id.

    Follow below Magento 2 API to get the customer order history.

    Request URL:
    https://magento.com/rest/V1/orders?searchCriteria%5Bfilter_groups%5D%5B0%5D%5Bfilters%5D%5B0%5D%5Bfield%5D=customer_email&searchCriteria%5Bfilter_groups%5D%5B0%5D%5Bfilters%5D%5B0%5D%5Bvalue%[email protected]

    Method: GET

    Response:

    {
        "items": [
            {
                "base_currency_code": "KWD",
                "base_discount_amount": 0,
                "base_grand_total": 40,
                "base_discount_tax_compensation_amount": 0,
                "base_shipping_amount": 10,
                "base_shipping_discount_amount": 0,
                "base_shipping_discount_tax_compensation_amnt": 0,
                "base_shipping_incl_tax": 10,
                "base_shipping_tax_amount": 0,
                "base_subtotal": 30,
                "base_subtotal_incl_tax": 30,
                "base_tax_amount": 0,
                "base_total_due": 40,
                "base_to_global_rate": 1,
                "base_to_order_rate": 1,
                "billing_address_id": 250,
                "created_at": "2019-08-14 11:26:48",
                "customer_email": "[email protected]",
                "customer_firstname": "Test",
                "customer_group_id": 1,
                "customer_id": 51,
                "customer_is_guest": 0,
                "customer_lastname": "Customer",
                "customer_note_notify": 1,
                "discount_amount": 0,
                "email_sent": 1,
                "entity_id": 125,
                "global_currency_code": "KWD",
                "grand_total": 40,
                "discount_tax_compensation_amount": 0,
                "increment_id": "000000119",
                "is_virtual": 0,
                "order_currency_code": "KWD",
                "protect_code": "9a7b171724410d42aec193ba5206901e",
                "quote_id": 398,
                "remote_ip": "202.131.115.180",
                "shipping_amount": 10,
                "shipping_description": "Flat Rate - Fixed",
                "shipping_discount_amount": 0,
                "shipping_discount_tax_compensation_amount": 0,
                "shipping_incl_tax": 10,
                "shipping_tax_amount": 0,
                "state": "new",
                "status": "pending",
                "store_currency_code": "KWD",
                "store_id": 1,
                "store_name": "Default Store",
                "store_to_base_rate": 0,
                "store_to_order_rate": 0,
                "subtotal": 30,
                "subtotal_incl_tax": 30,
                "tax_amount": 0,
                "total_due": 40,
                "total_item_count": 1,
                "total_qty_ordered": 2,
                "updated_at": "2019-08-14 11:26:49",
                "weight": 0,
                "items": [
                    {
                        "amount_refunded": 0,
                        "base_amount_refunded": 0,
                        "base_cost": 8.5,
                        "base_discount_amount": 0,
                        "base_discount_invoiced": 0,
                        "base_discount_tax_compensation_amount": 0,
                        "base_original_price": 15,
                        "base_price": 15,
                        "base_price_incl_tax": 15,
                        "base_row_invoiced": 0,
                        "base_row_total": 30,
                        "base_row_total_incl_tax": 30,
                        "base_tax_amount": 0,
                        "base_tax_invoiced": 0,
                        "created_at": "2019-08-14 11:26:48",
                        "discount_amount": 0,
                        "discount_invoiced": 0,
                        "discount_percent": 0,
                        "free_shipping": 0,
                        "discount_tax_compensation_amount": 0,
                        "is_qty_decimal": 0,
                        "is_virtual": 0,
                        "item_id": 341,
                        "name": "DIAMOND GLITTER GRAY",
                        "no_discount": 0,
                        "order_id": 125,
                        "original_price": 15,
                        "price": 15,
                        "price_incl_tax": 15,
                        "product_id": 228,
                        "product_type": "simple",
                        "qty_canceled": 0,
                        "qty_invoiced": 0,
                        "qty_ordered": 2,
                        "qty_refunded": 0,
                        "qty_shipped": 0,
                        "quote_item_id": 1281,
                        "row_invoiced": 0,
                        "row_total": 30,
                        "row_total_incl_tax": 30,
                        "row_weight": 0,
                        "sku": "CLBELGLG0175DCMO",
                        "store_id": 1,
                        "tax_amount": 0,
                        "tax_invoiced": 0,
                        "tax_percent": 0,
                        "updated_at": "2019-08-14 11:26:48"
                    }
                ],
                "billing_address": {
                    "address_type": "billing",
                    "city": "California",
                    "company": "Company",
                    "country_id": "US",
                    "email": "[email protected]",
                    "entity_id": 250,
                    "firstname": "john",
                    "lastname": "harrison",
                    "parent_id": 125,
                    "postcode": "12345",
                    "region": "New York",
                    "region_code": "NY",
                    "region_id": 43,
                    "street": [
                        "Street Address"
                    ],
                    "telephone": "2313131312"
                },
                "payment": {
                    "account_status": null,
                    "additional_information": [
                        "Check / Money order"
                    ],
                    "amount_ordered": 40,
                    "base_amount_ordered": 40,
                    "base_shipping_amount": 10,
                    "cc_exp_year": "0",
                    "cc_last4": null,
                    "cc_ss_start_month": "0",
                    "cc_ss_start_year": "0",
                    "entity_id": 125,
                    "method": "checkmo",
                    "parent_id": 125,
                    "shipping_amount": 10
                },
                "status_histories": [],
                "extension_attributes": {
                    "shipping_assignments": [
                        {
                            "shipping": {
                                "address": {
                                    "address_type": "shipping",
                                    "city": "California",
                                    "company": "Company",
                                    "country_id": "US",
                                    "email": "[email protected]",
                                    "entity_id": 249,
                                    "firstname": "john",
                                    "lastname": "harrison",
                                    "parent_id": 125,
                                    "postcode": "12345",
                                    "region": "New York",
                                    "region_code": "NY",
                                    "region_id": 43,
                                    "street": [
                                        "Street Address"
                                    ],
                                    "telephone": "2313131312"
                                },
                                "method": "flatrate_flatrate",
                                "total": {
                                    "base_shipping_amount": 10,
                                    "base_shipping_discount_amount": 0,
                                    "base_shipping_discount_tax_compensation_amnt": 0,
                                    "base_shipping_incl_tax": 10,
                                    "base_shipping_tax_amount": 0,
                                    "shipping_amount": 10,
                                    "shipping_discount_amount": 0,
                                    "shipping_discount_tax_compensation_amount": 0,
                                    "shipping_incl_tax": 10,
                                    "shipping_tax_amount": 0
                                }
                            },
                            "items": [
                                {
                                    "amount_refunded": 0,
                                    "base_amount_refunded": 0,
                                    "base_cost": 8.5,
                                    "base_discount_amount": 0,
                                    "base_discount_invoiced": 0,
                                    "base_discount_tax_compensation_amount": 0,
                                    "base_original_price": 15,
                                    "base_price": 15,
                                    "base_price_incl_tax": 15,
                                    "base_row_invoiced": 0,
                                    "base_row_total": 30,
                                    "base_row_total_incl_tax": 30,
                                    "base_tax_amount": 0,
                                    "base_tax_invoiced": 0,
                                    "created_at": "2019-08-14 11:26:48",
                                    "discount_amount": 0,
                                    "discount_invoiced": 0,
                                    "discount_percent": 0,
                                    "free_shipping": 0,
                                    "discount_tax_compensation_amount": 0,
                                    "is_qty_decimal": 0,
                                    "is_virtual": 0,
                                    "item_id": 341,
                                    "name": "BELLA DIAMOND GLITTER GRAY 0175",
                                    "no_discount": 0,
                                    "order_id": 125,
                                    "original_price": 15,
                                    "price": 15,
                                    "price_incl_tax": 15,
                                    "product_id": 228,
                                    "product_type": "simple",
                                    "qty_canceled": 0,
                                    "qty_invoiced": 0,
                                    "qty_ordered": 2,
                                    "qty_refunded": 0,
                                    "qty_shipped": 0,
                                    "quote_item_id": 1281,
                                    "row_invoiced": 0,
                                    "row_total": 30,
                                    "row_total_incl_tax": 30,
                                    "row_weight": 0,
                                    "sku": "CLBELGLG0175DCMO",
                                    "store_id": 1,
                                    "tax_amount": 0,
                                    "tax_invoiced": 0,
                                    "tax_percent": 0,
                                    "updated_at": "2019-08-14 11:26:48"
                                }
                            ]
                        }
                    ],
                    "rewards_discount": 0,
                    "rewards_spend": 0,
                    "rewards_earn": 950
                }
            },
            {
                "applied_rule_ids": "4,11",
                "base_currency_code": "KWD",
                "base_discount_amount": -15,
                "base_grand_total": 165,
                "base_discount_tax_compensation_amount": 0,
                "base_shipping_amount": 45,
                "base_shipping_discount_amount": 0,
                "base_shipping_discount_tax_compensation_amnt": 0,
                "base_shipping_incl_tax": 45,
                "base_shipping_tax_amount": 0,
                "base_subtotal": 135,
                "base_subtotal_incl_tax": 135,
                "base_tax_amount": 0,
                "base_total_due": 165,
                "base_to_global_rate": 1,
                "base_to_order_rate": 1,
                "billing_address_id": 268,
                "created_at": "2019-09-24 13:16:32",
                "customer_email": "[email protected]",
                "customer_firstname": "Test",
                "customer_group_id": 1,
                "customer_id": 51,
                "customer_is_guest": 0,
                "customer_lastname": "Customer",
                "customer_note_notify": 1,
                "discount_amount": -15,
                "email_sent": 1,
                "entity_id": 134,
                "global_currency_code": "KWD",
                "grand_total": 165,
                "discount_tax_compensation_amount": 0,
                "increment_id": "000000128",
                "is_virtual": 0,
                "order_currency_code": "KWD",
                "protect_code": "1deccd785628b2df682d9156db732fc0",
                "quote_id": 408,
                "shipping_amount": 45,
                "shipping_description": "Flat Rate - Fixed",
                "shipping_discount_amount": 0,
                "shipping_discount_tax_compensation_amount": 0,
                "shipping_incl_tax": 45,
                "shipping_tax_amount": 0,
                "state": "new",
                "status": "pending",
                "store_currency_code": "KWD",
                "store_id": 1,
                "store_name": "Default Store",
                "store_to_base_rate": 0,
                "store_to_order_rate": 0,
                "subtotal": 135,
                "subtotal_incl_tax": 135,
                "tax_amount": 0,
                "total_due": 165,
                "total_item_count": 1,
                "total_qty_ordered": 9,
                "updated_at": "2019-09-24 13:16:33",
                "weight": 0,
                "items": [
                    {
                        "amount_refunded": 0,
                        "applied_rule_ids": "4,11",
                        "base_amount_refunded": 0,
                        "base_cost": 8.5,
                        "base_discount_amount": 15,
                        "base_discount_invoiced": 0,
                        "base_discount_tax_compensation_amount": 0,
                        "base_original_price": 15,
                        "base_price": 15,
                        "base_price_incl_tax": 15,
                        "base_row_invoiced": 0,
                        "base_row_total": 135,
                        "base_row_total_incl_tax": 135,
                        "base_tax_amount": 0,
                        "base_tax_invoiced": 0,
                        "created_at": "2019-09-24 13:16:32",
                        "discount_amount": 15,
                        "discount_invoiced": 0,
                        "discount_percent": 0,
                        "free_shipping": 0,
                        "discount_tax_compensation_amount": 0,
                        "is_qty_decimal": 0,
                        "is_virtual": 0,
                        "item_id": 351,
                        "name": "BELLA DIAMOND GLITTER GRAY 0175",
                        "no_discount": 0,
                        "order_id": 134,
                        "original_price": 15,
                        "price": 15,
                        "price_incl_tax": 15,
                        "product_id": 228,
                        "product_type": "simple",
                        "qty_canceled": 0,
                        "qty_invoiced": 0,
                        "qty_ordered": 9,
                        "qty_refunded": 0,
                        "qty_shipped": 0,
                        "quote_item_id": 1378,
                        "row_invoiced": 0,
                        "row_total": 135,
                        "row_total_incl_tax": 135,
                        "row_weight": 0,
                        "sku": "CLBELGLG0175DCMO",
                        "store_id": 1,
                        "tax_amount": 0,
                        "tax_invoiced": 0,
                        "tax_percent": 0,
                        "updated_at": "2019-09-24 13:16:32"
                    }
                ],
                "billing_address": {
                    "address_type": "billing",
                    "city": "California",
                    "company": "Company",
                    "country_id": "US",
                    "email": "[email protected]",
                    "entity_id": 268,
                    "firstname": "john",
                    "lastname": "harrison",
                    "parent_id": 134,
                    "postcode": "12345",
                    "region": "New York",
                    "region_code": "NY",
                    "region_id": 43,
                    "street": [
                        "Street Address"
                    ],
                    "telephone": "2313131312"
                },
                "payment": {
                    "account_status": null,
                    "additional_information": [
                        "Check / Money order"
                    ],
                    "amount_ordered": 165,
                    "base_amount_ordered": 165,
                    "base_shipping_amount": 45,
                    "cc_exp_year": "0",
                    "cc_last4": null,
                    "cc_ss_start_month": "0",
                    "cc_ss_start_year": "0",
                    "entity_id": 134,
                    "method": "checkmo",
                    "parent_id": 134,
                    "shipping_amount": 45
                },
                "status_histories": [],
                "extension_attributes": {
                    "shipping_assignments": [
                        {
                            "shipping": {
                                "address": {
                                    "address_type": "shipping",
                                    "city": "California",
                                    "company": "Company",
                                    "country_id": "US",
                                    "email": "[email protected]",
                                    "entity_id": 267,
                                    "firstname": "john",
                                    "lastname": "harrison",
                                    "parent_id": 134,
                                    "postcode": "12345",
                                    "region": "New York",
                                    "region_code": "NY",
                                    "region_id": 43,
                                    "street": [
                                        "Street Address"
                                    ],
                                    "telephone": "2313131312"
                                },
                                "method": "flatrate_flatrate",
                                "total": {
                                    "base_shipping_amount": 45,
                                    "base_shipping_discount_amount": 0,
                                    "base_shipping_discount_tax_compensation_amnt": 0,
                                    "base_shipping_incl_tax": 45,
                                    "base_shipping_tax_amount": 0,
                                    "shipping_amount": 45,
                                    "shipping_discount_amount": 0,
                                    "shipping_discount_tax_compensation_amount": 0,
                                    "shipping_incl_tax": 45,
                                    "shipping_tax_amount": 0
                                }
                            },
                            "items": [
                                {
                                    "amount_refunded": 0,
                                    "applied_rule_ids": "4,11",
                                    "base_amount_refunded": 0,
                                    "base_cost": 8.5,
                                    "base_discount_amount": 15,
                                    "base_discount_invoiced": 0,
                                    "base_discount_tax_compensation_amount": 0,
                                    "base_original_price": 15,
                                    "base_price": 15,
                                    "base_price_incl_tax": 15,
                                    "base_row_invoiced": 0,
                                    "base_row_total": 135,
                                    "base_row_total_incl_tax": 135,
                                    "base_tax_amount": 0,
                                    "base_tax_invoiced": 0,
                                    "created_at": "2019-09-24 13:16:32",
                                    "discount_amount": 15,
                                    "discount_invoiced": 0,
                                    "discount_percent": 0,
                                    "free_shipping": 0,
                                    "discount_tax_compensation_amount": 0,
                                    "is_qty_decimal": 0,
                                    "is_virtual": 0,
                                    "item_id": 351,
                                    "name": "BELLA DIAMOND GLITTER GRAY 0175",
                                    "no_discount": 0,
                                    "order_id": 134,
                                    "original_price": 15,
                                    "price": 15,
                                    "price_incl_tax": 15,
                                    "product_id": 228,
                                    "product_type": "simple",
                                    "qty_canceled": 0,
                                    "qty_invoiced": 0,
                                    "qty_ordered": 9,
                                    "qty_refunded": 0,
                                    "qty_shipped": 0,
                                    "quote_item_id": 1378,
                                    "row_invoiced": 0,
                                    "row_total": 135,
                                    "row_total_incl_tax": 135,
                                    "row_weight": 0,
                                    "sku": "CLBELGLG0175DCMO",
                                    "store_id": 1,
                                    "tax_amount": 0,
                                    "tax_invoiced": 0,
                                    "tax_percent": 0,
                                    "updated_at": "2019-09-24 13:16:32"
                                }
                            ]
                        }
                    ],
                    "rewards_discount": 0,
                    "rewards_spend": 0,
                    "rewards_earn": 3770
                }
            }
        ],
        "search_criteria": {
            "filter_groups": [
                {
                    "filters": [
                        {
                            "field": "customer_email",
                            "value": "[email protected]",
                            "condition_type": "eq"
                        }
                    ]
                }
            ]
        },
        "total_count": 2
    }
    
    Login or Signup to reply.
  3. Magento default order API authenticate with admin.
    If you want to authenticate with customer.

    Please just create a new custom module and then create your own new API end-point.

    Add your new api end-point in VenderModuleetcwebapi.xml file.

    <!--Get Order by ID-->
    <route url="/V1/ca-orders/:id" method="GET">
        <service class="MagentoSalesApiOrderRepositoryInterface" method="get"/>
        <resources>
            <resource ref="self" />
        </resources>
    </route>
    <!--Get Order list-->
    <route url="/V1/ca-orders" method="GET">
        <service class="MagentoSalesApiOrderRepositoryInterface" method="getList"/>
        <resources>
            <resource ref="self" />
        </resources>
    </route>
    

    now you can use url http://magento.local/index.php/rest/V1/ca-orders?searchCriteria with customer auth token.

    Thank You!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search