com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Create and Publish an API from Swagger definition

Swagger definition is a format to describe REST APIs. In this tutorial you create and publish an API in WSO2 API Manager using Swagger definition, when you have 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.png
  3. Select I Have an Existing API. Select Swagger URL and type the "http://petstore.swagger.io/v2/swagger.json" URL in the text box. Click Start Creating
  4. Give the information in the table below.

    FieldSample value
    NamePetstore
    Context/petstore
    Version1.0.0
    VisibilityPublic
    Tagspets


  5. Notice that all the API resources are created automatically when the Swagger URL is specified.
  6. 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.
  7. Remove the security tag from the /pet POST resource given below. This is required to enable API invocation using API (store) console.

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

    Swagger - Get resource
    //remove the following code snippet
    
    security:
            - api_key: []
  9. After removing the security tags, click Apply Changes to save the changes.

    Click Next: Implement.
  10. Click the Managed API option. Enter the information in the table under the Implement tab. Click Next: Manage.

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

  11. Select options for Transports and Subscription Tiers.


    The options are 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.

    For more information on API authentication (e.g., non authentic API invocation), see HTTP methods.

  12. Click Save & Publish. 

Now you have successfully published an api using swagger defintion. Lets now invoke the API from 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 PetStore API from the Store.
  3. Subscribe to the API using the "DefaultApplication" and using "Gold" tier. For more information, see Subscribe to an API

  4. Click on View Subscriptions in the pop up. 

    You can view the APIs that the Default Application has subscribed.
  5. Click on Petstore - 1.0.0 from the API list. 

    Token generation

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

  6. Go to the API Console for the PetStore API
  7. Click on the POST pet resource and give the following example as the request body and click Try it out. Click to see the response.


    You have now successfully invoked the Petstore API.

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.