DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Using REST APIs [WSO2 API Manager]

Using REST APIs [WSO2 API Manager]

In this brief article, let's take a look at how easy it is to invoke the REST APIs of WSO2 API Manager.

Anupam Gogoi user avatar by
Anupam Gogoi
·
Oct. 29, 18 · Tutorial
Like (1)
Save
Tweet
Share
16.42K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

The WSO2 API Manager exposes a series of REST APIs and they are quite useful if you are going to create custom tools, solutions, for example, a Maven plugin. In this article, I'm going to explain how to use the APIs and in the next series of the articles, I'm going to show how to make use of the APIs to create a Maven plugin.

Getting Started

Here is the official documentation of the REST APIs. To invoke any API, first, we need to get a pair of clientId & client secret and then use them to get the access token. Here are the necessary steps,

Get ClientID and Client Secret

Method POST
Headers

Authorization: Base64(username:password)

Content-Type: application/json

URL

https://localhost:9443/client-registration/v0.13/register

Request
{
  "callbackUrl": "www.google.com",
  "clientName": "rest_api_publisher",
  "owner": "admin",
  "grantType": "password refresh_token",
  "saasApp": true
}


Response
{
    "clientId": "VapXbCr9XKTZJK3t_VNDtK5X2Ksa",
    "clientName": "admin_rest_api_publisher",
    "callBackURL": "www.google.lk",
    "clientSecret": "AA2b35yIOrqKzfxZVCxJ5OZH0Rwa",
    "isSaasApplication": true,
    "appOwner": null,
    "jsonString": "{\"grant_types\":\"password refresh_token\"}",
    "jsonAppAttribute": "{}",
    "tokenType": null
}


Getting Access Token

Note: Access token must be generated using the correct scope. In the below example, the scope (api_view) is used to generate access token to call an API to list available APIs. To generate access token to invoke an API to create an API, one must use api_create scope.

Method POST
Headers Authorization: Base64(clientId:clientSecret)

Content-Type: application/x-www-form-urlencoded

Request Params

grant_type: password

username: admin

password: admin

scope : apim:api_view

Response
{
    "access_token": "f6e21049-8f0f-3c05-b337-5f34b5fd4ea0",
    "refresh_token": "a7d60f0b-7360-3b11-92de-e8b4ffb26ea0",
    "scope": "apim:api_create",
    "token_type": "Bearer",
    "expires_in": 3600
}


Listing APIs

Once you have the access_token in hand, the following API can be called to list available APIs.

Method GET
Headers Authorization: Bearer <<ACCESS_TOKEN>>
Response
{
  "previous": "",
  "list": [
    {
      "provider": "admin",
      "version": "1.0.0",
      "description": "This sample API provides Account Status Validation",
      "name": "AccountVal",
      "context": "/account",
      "id": "2e81f147-c8a8-4f68-b4f0-69e0e7510b01",
      "status": "PUBLISHED"
    },
    {
      "provider": "admin",
      "version": "1.0.0",
      "description": null,
      "name": "api1",
      "context": "/api1",
      "id": "3e22d2fb-277a-4e9e-8c7e-1c0f7f73960e",
      "status": "PUBLISHED"
    }
  ],
  "next": "",
  "count": 2
}


Conclusion

In this brief article, I have shown how easy it is to invoke the REST APIs of WSO2 API Manager. For more detail, please go through the official documentation of WSO2. In the follow-up article, I'm going to explain how to create a Maven plugin to publish an API using the provided REST APIs.

API REST Web Protocols

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Was the Question Again, ChatGPT?
  • Microservices Discovery With Eureka
  • API Design Patterns Review
  • What Is a Kubernetes CI/CD Pipeline?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: