"Consumer is not authorized to access %resources"

Hello,

i am working on rest api.

i want to get all orders by customer.

below is url:

http://mydomainname.com/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=status&searchCriteria[filter_groups][0][filters][0][value]=pending

i got customer authorization error.

“Consumer is not authorized to access %resources”

when i remove $this->checkPermissions(); app/code/Magento/Webapi/Controller/Rest.php(286): it will work fine.

any idea?

You should setup permissions for the consumer.
See How to setup Magento 2 as an OAuth server?

already setup as per above process still same error. any thought?

i have to pass any key in api request?

To get started with the REST API in Magento 2, you will need token-based authentication. You will require to create a web service User Role and register that role to a new Magento 2 Admin User. Keep in mind that creating a new role and user is necessary because it’s not a good practice to use Magento Owner User in a web service.

To create a web service role in Magento 2, follow these steps:

  1. Login to the Magento 2 Admin Panel.
  2. Go to System > User Roles and tap the Add New Role
  3. Enter the Role Name.
  4. In Your Password field, enter the current password of your Magento 2 Admin.
  5. Now, on the left side, click Role Resources.
  6. In the Resource Access, select only those that are required for your web service.
  7. Once done, hit the Save Role.

Now, create a new user for the newly created role through these steps:

  1. Go to System > All Users and hit the Add New User
  2. Enter the required information including User Name, First and Last Name, Email, Password, etc.
  3. Now, on the left side, click User Role and select the newly created role.
  4. Once done, click the Save User.

That’s all; now you will use this user to the Magento 2 REST API web service.

For further reference, please go through of the below blog post:

Magento 2 REST API Tutorial for Developers