Generate requests from an API spec in Insomnia
Add an API spec to an API Collection and define your environment variables, then click the Spec tab. If the spec has no linting errors, the Generate button appears. Click it and select “Requests”. Insomnia adds a request for each endpoint in the spec so you can send requests while you’re still working on the design.
Prerequisites
An API Collection with a specification
You can either create an API Collection and design your specification from scratch, or import an existing specification. This example uses the Konnect API Products specification. Make sure that the specification doesn’t have any errors, otherwise the requests can’t be generated.
Configure an environment
If your API specification contains variables, you can use the environment to replace them with actual values in all the generated requests.
- Click Base Environment.
- Click the pencil icon to open the Manage Environment window.
-
Define the environment variables you need. In this example, you need to define at least the base URL and Personal Access Token:
{ "base_url": "https://us.api.konghq.com/v2", "bearerToken": "YOUR_PAT_TOKEN" }
Generate requests
- Open your API Collection and click the Spec tab.
- Click Generate.
- From the Generate dropdown menu, select “Requests”.
Insomnia adds a request for each endpoint in your specification. The requests display in the sidebar under your API Collection.
If the operations in the API spec have tags, the requests are organized into folders based on these tags. If an operation has multiple tags, the request is duplicated and appears in each folder. You can reorganize the requests as needed. For more information, see API Collections.
v13.3+ Generated requests live in the same API Collection as the spec, so you can reach them from the sidebar and from the Collections list. In Insomnia 13.2 and earlier, a collection generated from a design document was only reachable from the COLLECTION tab of that document.
Send requests
If the necessary environment variables are set, you can send a request right away. In this example using the Konnect API Products specification, you can send the List API Products request with only the base URL and Bearer token defined:
