Docs API
OpenAPI and Postman
Find the OpenAPI document and the Postman files of the API, import them into Postman, Insomnia or Bruno, and make them again.
The API has a machine-readable description in two formats: an OpenAPI document and a Postman collection. Use them to make a client, to test the API, or to load the API into a tool.
The files
The app repository has these files in docs/api/:
| File | Content |
|---|---|
docs/api/openapi.yaml |
The OpenAPI 3.1 document. It has each endpoint, with a summary, a description, the parameters, the request body, the responses and the error responses. |
docs/api/postman_collection.json |
A Postman v2.1 collection, with one folder for each tag of the document. |
docs/api/postman_environment.json |
A Postman environment with the baseUrl and token variables. |
public/docs/openapi.json has the same OpenAPI document as JSON.
The dedoc/scramble package makes the OpenAPI document from the code. It reads the routes, the controllers, the form requests and the API resources. The document is the contract of the API. CI makes the files again on each pull request, and fails when a committed file is not current.
The tags of the document are: Contacts, Lists, Topics, Tags, Newsletters, Sequences, Blocks, Email templates, Email identities, Email logs, Projects and Webhooks.
The document on an instance
Each instance also serves the document. These pages do not need a login.
| Path | Content |
|---|---|
/docs/api |
An interactive reference made from the document. |
/docs/api.json |
The document, made at request time from the current code. |
/documentation/openapi |
A download of public/docs/openapi.json, as byomailer-openapi-schema.json. |
The files in the repository use https://byomailer.example as the host. The /documentation/openapi route replaces that host with your APP_URL. If the static file does not exist, the route runs php artisan scramble:export first.
The API_VERSION environment variable sets info.version in the document. The default is 1.0.0.
The variables
The collection and the environment have two variables:
| Variable | Placeholder value | Set it to |
|---|---|---|
baseUrl |
https://app.example.com |
The URL of your instance, without /api/v1. For example https://mail.example.com. |
token |
YOUR_API_TOKEN |
An API token. See Authentication. |
Each request URL starts with {{baseUrl}}/api/v1. The collection sends token as a bearer token on each request.
Warning: Do not share or export a collection or an environment that contains your token. The token gives access to the data of your account.
Import into Postman
- Get
postman_collection.jsonandpostman_environment.jsonfromdocs/api/of the app repository. - In Postman, click Import.
- Select the two files.
- Open Environments and select the BYOMailer environment.
- Set
baseUrlto the URL of your instance. - Set
tokento your API token. Keep the type secret. - In the environment selector at the top right, select BYOMailer.
- Open a folder of the collection and send a request.
Each request in the collection has its optional query parameters turned off. Turn on a parameter before you use it.
Import into Insomnia
- Get
postman_collection.jsonfromdocs/api/of the app repository. - In Insomnia, click Import.
- Select the file. Insomnia makes a collection from it.
- Open the base environment of the collection.
- Set
baseUrlto the URL of your instance. - Set
tokento your API token. - Send a request.
Insomnia can also import openapi.yaml. Then Insomnia makes its own variables from the servers section, and the request URLs end in /api/v1. Use the Postman collection to keep the variables of this page.
Import into Bruno
- Get
postman_collection.jsonfromdocs/api/of the app repository. - In Bruno, click Import Collection.
- Select Postman Collection, then select the file.
- Select a folder for the new collection.
- Open the collection settings, then Vars.
- Set
baseUrlto the URL of your instance. - Set
tokento your API token. - Send a request.
To keep the token out of the collection files, put token in a Bruno environment and mark it as secret.
The Postman collection of the dashboard
The dashboard has its own collection. It is not the same file as docs/api/postman_collection.json.
GET /documentation/postman downloads byomailer-postman-collection.json. You can also click Download Postman Collection in Settings, API Tokens. This collection has one folder for each resource and two collection variables:
| Variable | Value |
|---|---|
base_url |
The APP_URL of the instance. |
api_token |
Empty. Put your API token here. |
The Markdown reference
GET /byomailer-docs.md returns the file public/docs/api-documentation.md as Markdown. It has request and response examples for each endpoint. The route replaces https://byomailer.example with your APP_URL.
Make the files again
If you add or change an API endpoint, make the files again in a development checkout of the app:
- Go to the folder of the app.
- Run the migrations. Scramble reads the column types from the database.
- Run
php artisan scramble:analyze. - If the command reports errors, correct them. Then run it again.
- Run
composer api-docs. - Read the diff of
docs/api/andpublic/docs/openapi.json. - Make sure that the diff has the new or changed endpoint, with its parameters, body and responses.
- Commit the files with your change.
php artisan migrate
php artisan scramble:analyze
composer api-docs
git diff docs/api public/docs/openapi.json
composer api-docs runs two commands:
php artisan byomailer:openapiwritesdocs/api/openapi.yamlandpublic/docs/openapi.json. The files usehttps://byomailer.exampleas the host, not yourAPP_URL.php artisan byomailer:postmanwrites the collection and the environment. It runs a pinned version ofopenapi-to-postmanv2withnpx, so it needs Node and network access the first time.
Do not run php artisan scramble:export for a commit. That command writes the host of your APP_URL into the file.
Run these commands in a development checkout of the app, not in a Docker container. The docker-compose.yml file does not mount the source code into the containers. So a file that you make in a container does not reach your checkout. See Installation with Docker.