Execute a GraphQL statement.
Description for api request graphql
Specify the GraphQL statement with the "--body" flag, either directly at the command line or with a file that contains the statement. You can query Salesforce records using a "query" statement or use mutations to modify Salesforce records.
This command uses the GraphQL API to query or modify Salesforce objects. For details about the API, and examples of queries and mutations, see https://developer.salesforce.com/docs/platform/graphql/guide/graphql-about.html.
Flags
| Flag Name (Long) | Flag Name (Short) | Description |
|---|---|---|
| <code>‑‑api‑version</code> | N/A | Type: Value<br><br>Override the api version used for api requests made by this command |
| <code>‑‑body</code> | N/A | Type: Value<br>Required<br><br>File or content with the GraphQL statement. Specify "-" to read from standard input. |
| <code>‑‑flags‑dir</code> | N/A | Type: Value<br><br>Import flag values from a directory. |
| <code>‑‑include</code> | <code>‑i</code> | Type: Boolean<br><br>Include the HTTP response status and headers in the output. |
| <code>‑‑json</code> | N/A | Type: Boolean<br><br>Format output as json. |
| <code>‑‑stream‑to‑file</code> | <code>‑S</code> | Type: Value<br><br>Stream responses to a file. |
| <code>‑‑target‑org</code> | <code>‑o</code> | Type: Value<br>Required<br><br>Username or alias of the target org. Not required if the target-org configuration variable is already set. |
Examples for api request graphql
Execute a GraphQL query on the Account object by specifying the query directly to the "--body" flag; the command uses your default org:
sf api request graphql --body "query accounts { uiapi { query { Account { edges { node { Id \n Name { value } } } } } } }"
Read the GraphQL statement from a file called "example.txt" and execute it on an org with alias "my-org":
sf api request graphql --body example.txt --target-org my-org
Pipe the GraphQL statement that you want to execute from standard input to the command:
echo graphql | sf api request graphql --body -
Write the output of the command to a file called "output.txt" and include the HTTP response status and headers:
sf api request graphql --body example.txt --stream-to-file output.txt --include
<!-- prettier-ignore-end -->