Consume Pet Store API using Postman

Manjula Rathnayake
Mar 30, 2018 · 2 min read

This demonstrate how to consume Pet Store API published in WSO2 API Cloud using postman collection. This assumes you have prior basic knowledge on postman. If not refer to https://medium.com/@mpmunasinghe/export-and-use-wso2-api-cloud-apis-through-postman-8dad6356253d first.

Complete API publish example at https://medium.com/@manjula.cse/publish-apis-using-swagger-postman-and-newman-3abffd91423c

  1. Refer to https://github.com/manjulaRathnayaka/API-Management-Examples/tree/master/consumeAPI to get the postman collection and data file.
    ├Default.postman_environment.json
    └TESTS_PET_STORE_API_IN_WSO2_API_CLOUD.postman_collection.js
  2. In Default.postman_environment.json file update tenantDomain value to match with your organization name in WSO2 API Cloud.

{
“enabled”: true,
“key”: “tenantDomain”,
“value”: “devcicd”,
“type”: “text”
}

3. Import the postman collection and environment json files to Postman.

Postman collection to get an access token

4. Set two global variables as username and password below.

username = your username in wso2 cloud (user@gmail.com@organizationName)

password = your password in wso2 cloud

5. Run postman runner.

If you use newman,

newman run TESTS_PET_STORE_API_IN_WSO2_API_CLOUD.postman_collection.json -e Default.postman_environment.json --global-var username=user@gmail.com@organizationName --global-var password=xxx

TESTS_PET_STORE_API_IN_WSO2_API_CLOUD

→ Dynamic Client Registration
POST https://gateway.api.cloud.wso2.com/client-registration/register [200 OK, 594B, 3s]

→ Get Access Token with apim:subscribe scope
POST https://gateway.api.cloud.wso2.com/token [200 OK, 447B, 852ms]

→ Get OAuth App
GET https://gateway.api.cloud.wso2.com/api/am/store/applications?query=testingApp [200 OK, 589B, 1850ms]

Attempting to set next request to Get API

→ Get API
GET https://gateway.api.cloud.wso2.com/api/am/store/apis?query=name:PetStore [200 OK, 654B, 748ms]

→ Subscribe to API
POST https://gateway.api.cloud.wso2.com/api/am/store/subscriptions [409 Conflict, 565B, 842ms]

→ Get Application Details
GET https://gateway.api.cloud.wso2.com/api/am/store/applications/1f881572-8ea4-44f4-842e-b12942773b01 [200 OK, 1.09KB, 466ms]

Attempting to set next request to Generate Access Token

→ Generate Access Token
POST https://gateway.api.cloud.wso2.com/token [200 OK, 406B, 399ms]

→ Returns pet inventories by status
GET https://gateway.api.cloud.wso2.com:443/t/devcicd/petstore/1.0.0/store/inventory [200 OK, 557B, 6.8s]

│ ‘{“sold”:62,”pissedoff”:1,”green”:1,”string”:301,”-1":1,”pending”:47,”available”:5481,”1available”:1,”available;pending;sold”:5,”O
│ ffline”:1,”ad ut aliqua quis”:1,”kjk”:1,”AVAILABLE”:24,”onDemand”:1,”Sold”:2,”UNAVAILABLE”:15,”Available”:9,”availablez”:1,”status”:6}’

You can import the swagger file of your API into the postman project and continue invoking other APIs too. Refer to https://medium.com/@mpmunasinghe/export-and-use-wso2-api-cloud-apis-through-postman-8dad6356253d

You may use direct OAuth2 support in postman tool to get access token too.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade