This documentation is for WSO2 API Manager 2.5.0. View documentation for the latest release.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Tested and updated for 2.5.0 (screenshots, formatting, removing span tags, etc.)

A Swagger definition is a format to describe that describes REST APIs. In this tutorial, you create and publish an API in WSO2 API Manager using a Swagger definition , when you have for an existing API.

  1. Sign in to the WSO2 API Publisher. 
    https://<hostname>:9443/publisher (ex: https://localhost:9443/publisher).Use admin as username and password.
  2. In the APIS menu, click Add New API. 
    Add-New-API.pngImage RemovedImage Added
  3. Select Select I Have an Existing API. Select  Click Swagger URL and type the "give http://petstore.swagger.io/v2/swagger.json" URL in the text box as the URL. Click Start Creating.
    Image Modified
  4. Give Edit the information in the table as given below. 

    FieldSample value
    NamePetstore
    Context/petstore
    Version1.0.0
    VisibilityPublicTagspets

    Image Modified

  5. Notice that all the the API resources resources are created automatically when the Swagger URL is specified.
    Image RemovedImage Added
  6. Click Click Edit Source to edit the Swagger file and remove security headers. This is required to invoke the API in the Store using the Swagger UI.
    Image RemovedImage Added
  7. Remove the security tag from the /pet POST  POST resource given below. This is required to enable API invocation using the API (store) console.

    Code Block
    titleSwagger - Post resource
    //remove the following code snippet
    security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
  8. Remove the security pet/{petId} GET resource given below:

    Code Block
    titleSwagger - Get resource
    //remove the following code snippet
    
    security:
            - api_key: []
  9. After removing the security tags, click Apply Changes to save the changes.
    Image Modified
    Click Then, click Next: Implement.Image Removed
  10. Click the Managed API option. Enter the information in the table under the Implement tab. Click shown below and click Next: Manage.

    FieldSample value
    Endpoint typeHTTP/REST endpoint
    Production endpoint
    http://petstore.swagger.io/v2/
    Sandbox endpointProviding only the production endpoint
    only
    is
    suffieient
    sufficient.

    Image RemovedImage Added

  11. Select options for Transports and Subscription Tiers.Image Removed
    The options are the options described in the table given below.

    FieldSample valueDescription
    TransportsHTTP and HTTPSThe transport protocol on which the API is exposed.  Both HTTP and HTTPS transports are selected by default. If you want to limit API availability to only one transport (e.g., HTTPS), un-check the other transport.
    Subscription TiersGold, SilverThe API can be available at different levels of service. They allow you to limit the number of successful hits to an API during a given period of time.

    Image Added

  12. Click Save & Publish.
  13.  
  14.   

Now you have successfully published an

...

API using

...

a Swagger defintion.

...

Let's invoke the API from

...

the API Store.

Invoking the API

  1. Sign in to the WSO2 API Store.
    https://<hostname>:9443/store (ex: https://localhost:9443/store). Use admin as username and password

  2. Select the the PetStore API from the Store.
    Image Removedto open it.
  3. Subscribe to  to the API using the "DefaultApplication" and using "Gold" tier. For more information, see Subscribe to an API
    Image RemovedClick on View Subscriptions in the pop up. 
    Image Removed
    You can view the APIs that DefaultApplication and the Gold tier.
    Image Added
  4. Click View Subscriptions to view all the APIs to which the Default Application has subscribed.
    Image Removed
  5. Click on Petstore - 1.0.0 from the API list. 

    Info
    titleToken generation

    Generate the token for Default application, if you have not generated a token already/

    Image Removed

  6. Go Image Added
  7. Click the Production Keys tab and generate a token.
    Image Added

  8. Navigate to the API Console for  for the PetStore API.
    Image RemovedClick on the POST pet resource Image Added
  9. Expand the POST resource, click Try it out, and give the following example as the request body and click Try it out. Click to see . Click Execute and view the response.
    Image Removed

    Localtab Group
    Localtab
    activetrue
    titleRequest Body
    Code Block
    {
      "id": 0,
      "category": {
        "id": 0,
        "name": "Dogs"
      },
      "name": "Rover",
      "photoUrls": [
        "string"
      ],
      "tags": [
        {
          "id": 0,
          "name": "lion_shepard"
        }
      ],
      "status": "available"
    }
    Localtab
    titleResponse
    Code Block
    {
      "id": 9123612807670061000,
      "category": {
        "id": 0,
        "name": "Dogs"
      },
      "name": "Rover",
      "photoUrls": [
        "string"
      ],
      "tags": [
        {
          "id": 0,
          "name": "lion_shepard"
        }
      ],
      "status": "available"
    }



    You have now successfully invoked the Petstore API.

Info

Related Tutorials