Summary
Postman is a way to easily construct and test requests against an API.
Configuring with Discourse
-
After opening Postman, click Create Workspace:
-
Choose
Blank workspaceand click Next. -
Title it
Discourse APIand select Create: -
Click
Collections:
-
Click Import:
-
Paste
https://docs.discourse.org/openapi.json(which is the “Download” URL shown on docs.discourse.org):
-
Choose to import as a
Postman Collection:
Create a new Environment
-
Click on
EnvironmentsandCreate Environment. This will hold variables specific to the instance you’re testing. For this example, we’ll usetry.discourse.org.- add a new variable:
defaultHostwith the valuetry.discourse.org: - select the
try.discourse.orgenvironment from the ⑤ Environment dropdown
- add a new variable:
Hello World!
Let’s try a request!
- Select
Collections→categories.json→Retrieves a list of categoriesand click Send. You should see the result:
Add authentication to requests
To use the API with API key authentication:
-
Add the following variables to this or a new environment:
api-usernameapi-key
(their values must of course be valid for the site you are querying) -
Add a script to the collection
SelectCollections→Discourse API Documentation→Scripts→Pre-requestand paste the following:pm.request.headers.add({ key: "api-key", value: pm.variables.get("api-key") }) pm.request.headers.add({ key: "api-username", value: pm.variables.get("api-username") })









