Export Features Guide
Laravel Spectrum can export generated OpenAPI documents to formats that can be imported directly into Postman and Insomnia.
Postman Export
Basic Export
php artisan spectrum:export:postman
Default outputs:
storage/app/spectrum/postman/postman_collection.jsonstorage/app/spectrum/postman/postman_environment_local.json
Available Options
--output=: Output directory--environments=: Environments to export (comma-separated, defaultlocal)--single-file: Embed environments into the collection instead of separate files
Examples
# Use default output directory
php artisan spectrum:export:postman
# Export to custom directory
php artisan spectrum:export:postman --output=storage/app/exports/postman
# Export multiple environments
php artisan spectrum:export:postman --environments=local,staging,production
# Embed environments into one collection file
php artisan spectrum:export:postman --single-file --environments=local,staging
Insomnia Export
Basic Export
php artisan spectrum:export:insomnia
Default output:
storage/app/spectrum/insomnia/insomnia_collection.json
Available Options
--output=: Output file path or output directory
When --output is a directory (or ends with /), Laravel Spectrum writes insomnia_collection.json into that directory.
Examples
# Use default output path
php artisan spectrum:export:insomnia
# Export to explicit file path
php artisan spectrum:export:insomnia --output=storage/app/exports/insomnia/api.json
# Export to directory (filename is appended automatically)
php artisan spectrum:export:insomnia --output=storage/app/exports/insomnia/
Import Procedures
Importing to Postman
- Open Postman.
- Click "Import".
- Select
postman_collection.json. - Import the corresponding
postman_environment_*.jsonfile (unless--single-filewas used). - Select your environment and run requests.
Importing to Insomnia
- Open Insomnia.
- Go to
Application -> Preferences -> Data -> Import Data. - Select
From File. - Choose the exported
insomnia_collection.json(or your custom output file).
CI Example
# .github/workflows/export-api.yml
name: Export API Documentation
on:
push:
branches: [main]
jobs:
export:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install dependencies
run: composer install --no-interaction --prefer-dist
- name: Export Postman collection
run: php artisan spectrum:export:postman --environments=local,staging
- name: Export Insomnia collection
run: php artisan spectrum:export:insomnia