---
schema_version: "1"
id: 61e2cda44ff2664a56e2b7bba5d8e8c2b0a693c4cbbbaef47b17c7815cce3ca9
title: api request rest
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/sfclireference/guides/api/cli_reference_api_request_rest.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-cli-reference/guide/cli_reference_api_request_rest.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5fc53c4b65270c389dc17b06792bf37353040133ecddce98712a0d2157b6d630
products:
  - Salesforce CLI Command Reference
  - salesforcedx
---
<!-- prettier-ignore-start -->

# api request rest

Make an authenticated HTTP request using the Salesforce REST API.

## Description for api request rest

When sending the HTTP request with the "--body" flag, you can specify the request directly at the command line or with a file that contains the request.

For a full list of supported REST endpoints and resources, see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_list.htm.

## Flags

| Flag Name (Long) | Flag Name (Short) | Description |
|------------------|-------------------|-------------|
| <code>&#8209;&#8209;body</code> | <code>&#8209;b</code> | **Type:** Value<br><br>File or content for the body of the HTTP request. Specify "-" to read from standard input or "" for an empty body. If passing a file, prefix the filename with '@'. |
| <code>&#8209;&#8209;file</code> | <code>&#8209;f</code> | **Type:** Value<br><br>JSON file that contains values for the request header, body, method, and URL.<br><br>Use this flag instead of specifying the request details with individual flags, such as --body or --method. This schema defines how to create the JSON file:<br><br>{<br><br>url: { raw: string } &#124; string;<br><br>method: 'GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE';<br><br>description?: string;<br><br>header: string &#124; Array&lt;Record&lt;string, string&gt;&gt;;<br><br>body: { mode: 'raw' &#124; 'formdata'; raw: string; formdata: FormData };<br><br>}<br><br>Salesforce CLI defined this schema to be mimic Postman schemas; both share similar properties. The CLI's schema also supports Postman Collections to reuse and share requests. As a result, you can build an API call using Postman, export and save it to a file, and then use the file as a value to this flag. For information about Postman, see https://learning.postman.com/.<br><br>Here's a simple example of a JSON file that contains values for the request URL, method, and body:<br><br>{<br><br>"url": "sobjects/Account/&lt;Account ID&gt;",<br><br>"method": "PATCH",<br><br>"body" : {<br><br>"mode": "raw",<br><br>"raw": {<br><br>"BillingCity": "Boise"<br><br>}<br><br>}<br><br>}<br><br>See more examples in the plugin-api test directory, including JSON files that use "formdata" to define collections: https://github.com/salesforcecli/plugin-api/tree/main/test/test-files/data-project. |
| <code>&#8209;&#8209;flags&#8209;dir</code> | N/A | **Type:** Value<br><br>Import flag values from a directory. |
| <code>&#8209;&#8209;header</code> | <code>&#8209;H</code> | **Type:** Value<br><br>HTTP header in "key:value" format. |
| <code>&#8209;&#8209;include</code> | <code>&#8209;i</code> | **Type:** Boolean<br><br>Include the HTTP response status and headers in the output. |
| <code>&#8209;&#8209;json</code> | N/A | **Type:** Boolean<br><br>Format output as json. |
| <code>&#8209;&#8209;method</code> | <code>&#8209;X</code> | **Type:** Value<br>**Valid Values:** `GET`, `POST`, `PUT`, `PATCH`, `HEAD`, `DELETE`, `OPTIONS`, `TRACE`<br><br>HTTP method for the request. |
| <code>&#8209;&#8209;stream&#8209;to&#8209;file</code> | <code>&#8209;S</code> | **Type:** Value<br><br>Stream responses to a file. |
| <code>&#8209;&#8209;target&#8209;org</code> | <code>&#8209;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 rest

List information about limits in the org with alias "my-org":

```shell
sf api request rest 'services/data/v56.0/limits' --target-org my-org
```

List all endpoints in your default org; write the output to a file called "output.txt" and include the HTTP response status and headers:

```shell
sf api request rest '/services/data/v56.0/' --stream-to-file output.txt --include
```

Get the response in XML format by specifying the "Accept" HTTP header:

```shell
sf api request rest '/services/data/v56.0/limits' --header 'Accept: application/xml'
```

Create an account record using the POST method; specify the request details directly in the "--body" flag:

```shell
sf api request rest /services/data/v56.0/sobjects/account --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \"Boise\"}" --method POST
```

Create an account record using the information in a file called "info.json" (note the @ prefixing the file name):

```shell
sf api request rest '/services/data/v56.0/sobjects/account' --body @info.json --method POST
```

Update an account record using the PATCH method:

```shell
sf api request rest '/services/data/v56.0/sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method PATCH
```

Store the values for the request header, body, and so on, in a file, which you then specify with the --file flag; see the description of --file for more information:

```shell
sf api request rest --file myFile.json
```
<!-- prettier-ignore-end -->
