api request graphql (Beta)

Execute a GraphQL statement.

This feature is a Beta Service. Customers may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms.

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.

Flag Name (Long)Flag Name (Short)Description
‑‑api‑versionN/AType: Value

Override the api version used for api requests made by this command
‑‑bodyN/AType: Value
Required

File or content with the GraphQL statement. Specify ”-” to read from standard input.
‑‑flags‑dirN/AType: Value

Import flag values from a directory.
‑‑include‑iType: Boolean

Include the HTTP response status and headers in the output.
‑‑jsonN/AType: Boolean

Format output as json.
‑‑stream‑to‑file‑SType: Value

Stream responses to a file.
‑‑target‑org‑oType: Value
Required

Username or alias of the target org. Not required if the target-org configuration variable is already set.

Execute a GraphQL query on the Account object by specifying the query directly to the “–body” flag; the command uses your default org:

Read the GraphQL statement from a file called “example.txt” and execute it on an org with alias “my-org”:

Pipe the GraphQL statement that you want to execute from standard input to the command:

Write the output of the command to a file called “output.txt” and include the HTTP response status and headers: