DEV Community

Paboda Hettiarachchi
Paboda Hettiarachchi

Posted on • Edited on

8 1

Swagger - Magento 2

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"}]}
Enter fullscreen mode Exit fullscreen mode

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

  1. SYSTEM > Extensions > Integrations > Add New Integration
  2. Give a name like "TestAPI"
  3. Enter the current user's password
  4. Go to API tab and select the sections (I usually mark all)
  5. Save
  6. In the list of Integrations, click on "Activate" in Activate column for the integration you created Alt Text
  7. Allow the list of actions
  8. Click on "Done"
  9. There will be 4 values generated Alt Text

To Configure Swagger with API key

  1. Give the value of "Access Token" in SYSTEM > Extensions > Integrations > Add New Integration > Integration record > Integration Info Tab > Integration Details, as the api_key Alt Text
  2. 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".
Alt Text

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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay