Everytime I have to test API calls in a project, I need to search the configurations that need to be done. So finally thought of writing a simple blog post I end up using.
I have used two API testing methods for Magento.
- Postman (there is a Chrome plugin available)
- Swagger (which is inbuilt in Magento 2)
NOTE:
Please check https://github.com/dotmailer/dotmailer-magento2-extension/issues/557 before starting as there might be an error
{"schemaValidationMessages":[{"level":"error","message":"Can't read from file http://paboda.order.local/rest/all/schema?services=all"}]}
Link to access: your_magento_url/swagger
By default there will be a few of API calls available but to use all methods we need to
- create an integration user in Magento backend
- configure Swagger with API key
To create inegration user in Magento Backend
- SYSTEM > Extensions > Integrations > Add New Integration
- Give a name like "TestAPI"
- Enter the current user's password
- Go to API tab and select the sections (I usually mark all)
- Save
- In the list of Integrations, click on "Activate" in Activate column for the integration you created
- Allow the list of actions
- Click on "Done"
- There will be 4 values generated
To Configure Swagger with API key
- Give the value of "Access Token" in SYSTEM > Extensions > Integrations > Add New Integration > Integration record > Integration Info Tab > Integration Details, as the api_key
- Click on apply
There will be API calls available to be executed.
Another setting related to API calls is as the following. The default value will be "No".
To fix "The consumer isn't authorized to access %resources." even when the access token is given,
bin/magento config:set oauth/consumer/enable_integration_as_bearer 1
Top comments (0)