If you want to programmatically control the ngrok agent, the Agent
SDKs are usually a more flexible and powerful choice.
Overview
The ngrok agent exposes an HTTP API that enables programmatic access of:- Collect status and metrics information
- Collect and replay captured requests
- Start and stop endpoints dynamically
Base URL and Authentication
Base URL | http://127.0.0.1:4040/api |
Authentication | None |
web_addr
in your configuration file.
Access the root API resource of a running ngrok agent
Supported Content Types
Request parameters must be encoded to the API usingapplication/json
. Ensure that your client sets the request’s Content-Type
header appropriately. All responses returned by the API are application/json
.
Versioning and API Stability
The ngrok agent API guarantees that breaking changes to the API will never be made unless the caller explicitly opts in to a newer version. The mechanism by which a caller opts into a new version of the API will be determined in the future when it becomes necessary. Examples of non-breaking changes to the API that will not be opt-in include the following.- The addition of new resources
- The addition of new methods to existing resources
- The addition of new fields on existing resource representations
- Bug fixes which change the API to match documented behavior
The ngrok agent API accessible at
http://localhost:4040/api
supports only the v2 agent configuration format. If you are using or planning to use configuration version 3, refer to the Agent Config Version 3 documentation for guidance.List Tunnels
Returns a list of running tunnels with status and metrics information.Request
GET/api/tunnelsResponse
Parameters
tunnels | list of all running tunnels. See the Tunnel detail resource for docs on the parameters of each tunnel object |
Example Response
Start tunnel
Dynamically starts a new tunnel on the ngrok agent. The request body parameters are the same as those you would use to define the tunnel in the configuration file.Request
POST/api/tunnelsParameters
Parameter names and behaviors are identical to those those defined in the configuration file. Use the tunnel definitions section as a reference for configuration parameters and their behaviors.Example request body
Response
201 status code with a response body describing the started tunnel. See the Tunnel detail resource for docs on the parameters of the response objectExample Response
Tunnel detail
Get status and metrics about the named running tunnelRequest
GET/api/tunnels/:nameResponse
Example Response
Stop tunnel
Stop a running tunnelRequest
DELETE/api/tunnels/:nameResponse
204 status code with an empty bodyList Captured Requests
Returns a list of all HTTP requests captured for inspection. This will only return requests that are still in memory (ngrok evicts captured requests when their memory usage exceedsinspect_db_size
)
Request
GET/api/requests/httpQuery Parameters
limit | maximum number of requests to return |
tunnel_name | filter requests only for the given tunnel name |
Example Request
Response
requests | list of captured requests. See the Captured Request Detail resource for docs on the request objects |
Example Response
Replay Captured Request
Replays a request against the local endpoint of a tunnelRequest
POST/api/requests/httpParameters
id | id of request to replay |
tunnel_name | name of the tunnel to play the request against. If unspecified, the request is played against the same tunnel it was recorded on |
Example Request
Response
204 status code with an empty bodyDelete Captured Requests
Deletes all captured requestsRequest
DELETE/api/requests/httpResponse
204 status code with no response bodyCaptured Request Detail
Returns metadata and raw bytes of a captured request. The raw data is base64-encoded in the JSON response. Theresponse
value maybe null
if the local server has not yet responded to a request.