add_draft_from_curl
Creates a draft request from a curl command.
Overview
add_draft_from_curl turns a curl command into a draft in Relay's sidebar, the same way File > Import > cURL Command… does. Relay parses the command and never runs it. Options Relay can't represent are reported as warnings.
{
"command": "curl -X POST https://api.example.com/v2/orders -H 'Content-Type: application/json' -d '{\"sku\":\"A-100\",\"quantity\":2}'",
"name": "Create Order"
}A command whose URL starts with ws:// or wss:// creates a WebSocket request.
Parameters
Prop
Type
Return Value
The same object as add_draft:
{
"draftId": "2E6A9C13-7B4F-4D08-A5E1-9F3B7D2C6A80",
"name": "Create Order",
"method": "POST",
"kind": "http",
"url": "https://api.example.com/v2/orders",
"workspaceId": null,
"workspaceName": null,
"warnings": []
}Prop
Type
Discussion
The command is read like a shell would read it, with single, double and $'…' quotes and backslash line continuations. Relay maps the options it can, such as -X, -H, -d, --json, -F, -u, -b, -L, -k and -m, onto the draft's method, headers, body, auth and settings. Options that only control how curl runs, such as -s or -v, are ignored with a warning.
The tool returns an error, with the reason, when the command:
- Doesn't start with
curlor has no URL. - Has more than one URL, or uses
--next. - Uses shell command substitution: backticks or
$(…)outside single quotes. - Reads a body, header, cookie or credentials from a file or standard input.
- Mixes
--dataand--formbodies. - Uses an option Relay doesn't support.
For the options Relay supports, see Importing cURL commands.
See Also
- add_draft: Creates a draft request from a URL, method, headers, body and settings.
- Importing cURL commands: Turn a cURL command into a draft request.
- Supported formats: The import formats, body types, auth types and limits Relay supports.