get_scripts
Reads the scripts of a request, folder or collection.
Overview
get_scripts returns the JavaScript a request, folder or collection runs before its requests are sent (preRequest) and after their responses arrive (postResponse). Pass exactly one of requestId, folderId or collectionId.
{
"requestId": "5B2C8E41-9D3A-4F67-B0E8-1A4C7D2F6E95"
}For a request, the result also lists the collection and folder scripts that run around it, outermost first.
Parameters
Prop
Type
Return Value
{
"kind": "request",
"id": "5B2C8E41-9D3A-4F67-B0E8-1A4C7D2F6E95",
"name": "Create Order",
"preRequest": "",
"postResponse": "test(\"returns 201\", () => {\n expect(relay.response.code).toBe(201);\n});",
"enabled": true,
"approved": true,
"inherited": [
{
"kind": "collection",
"id": "A1F3D5B7-0C2E-4A6B-8D9F-1E3C5A7B9D02",
"name": "Orders",
"preRequest": "relay.request.headers.add({ key: \"X-Request-Id\", value: relay.variables.replaceIn(\"{{$guid}}\") });",
"postResponse": "",
"enabled": true,
"approved": false
},
{
"kind": "folder",
"id": "E8F14A3B-2C6D-4B9E-A0F7-5D1C3B8A9E26",
"name": "Checkout",
"preRequest": "",
"postResponse": "",
"enabled": true,
"approved": true
}
]
}Prop
Type
Discussion
When a request is sent, the collection's scripts run first, then each folder's from the outermost in, then the request's own, in each phase. Scripts that are turned off, or that haven't been approved, are skipped. For a folder, inherited isn't included.
A script is unapproved when it was written by set_scripts, imported, or changed in the workspace's folder outside Relay, until you review it and click Allow in the Scripts tab or in Collection Settings.
The tool returns an error when you pass more or fewer than one id, or when the id doesn't exist.
See Also
- set_scripts: Replaces the scripts of a request, folder or collection.
- Running scripts before and after requests: Add pre-request and post-response scripts to requests, folders and collections.
- Allowing scripts to run: Review and allow scripts that changed outside Relay before they run.