add_draft
Creates a draft request from a URL, method, headers, body and settings.
Overview
add_draft adds a request to the Drafts section of Relay's sidebar, where you can review it, send it and save it to a collection. Only url is required. A query string in the URL is split into rows of the Params tab, and the method defaults to GET, or POST when you give a body.
{
"name": "Create Order",
"url": "{{baseUrl}}/orders?notify=false",
"headers": [{ "key": "Accept", "value": "application/json" }],
"body": {
"type": "json",
"content": { "sku": "{{sku}}", "quantity": 2 }
},
"workspaceId": "7D1E6C2A-4F0B-4C55-9A57-3B8E2F1D9C40"
}With kind set to websocket, the draft is a WebSocket request instead. It has no method or body, and takes subprotocols and saved messages. Relay doesn't open the connection; you do.
Parameters
Prop
Type
Key-value rows
headers, queryParams and a form body's fields are arrays of rows:
Prop
Type
Body
Prop
Type
Settings
Each setting overrides the default from the Network pane of Relay's settings. Leave one out to inherit it.
Prop
Type
Messages
Prop
Type
Return Value
{
"draftId": "9C4B2E70-3A5D-4F81-B6E2-7D0A1C3F5B48",
"name": "Create Order",
"method": "POST",
"kind": "http",
"url": "{{baseUrl}}/orders",
"workspaceId": "7D1E6C2A-4F0B-4C55-9A57-3B8E2F1D9C40",
"workspaceName": "Orders API",
"warnings": []
}Prop
Type
Discussion
The draft's auth is set to inherit, so it uses the auth of its workspace and then the global auth, unless its headers set an Authorization header themselves. Drafts don't inherit from collections or folders.
A draft without workspaceId isn't tied to any workspace. Every window lists it under Drafts and shows it with the variables, environment and auth of the window's own workspace. It joins that workspace when you edit or send it in that window.
Relay adjusts some requests and reports each change in warnings:
- A GET, HEAD or TRACE request with a body becomes a POST, because those methods can't carry a body in Relay.
- A multipart part with
isFileset is kept, with a warning that Relay must be able to read the file's path when it sends the request. - For a WebSocket request,
methodandbodyare ignored. Send content asmessagesinstead.
The tool returns an error for an empty URL, an unknown kind or body type, a method that isn't a valid token, a timeout that isn't more than 0, a maximumRedirects that isn't a whole number of at least 1, a binary message that isn't base64, or a workspaceId no workspace has.
See Also
- add_draft_from_curl: Creates a draft request from a curl command.
- Creating and managing requests: Keep requests as drafts or save them in collections, and rename, duplicate and open them in their own windows.
- Supported formats: The import formats, body types, auth types and limits Relay supports.