@@ -60,7 +60,7 @@ sf plugins
6060<!-- commands -->
6161
6262- [ ` sf api request graphql ` ] ( #sf-api-request-graphql )
63- - [ ` sf api request rest ENDPOINT ` ] ( #sf-api-request-rest-endpoint )
63+ - [ ` sf api request rest [URL] ` ] ( #sf-api-request-rest-url )
6464
6565## ` sf api request graphql `
6666
@@ -113,31 +113,33 @@ EXAMPLES
113113 $ sf api request graphql --body example.txt --stream-to-file output.txt --include
114114```
115115
116- _ See code: [ src/commands/api/request/graphql.ts] ( https://github.com/salesforcecli/plugin-api/blob/1.2.2 /src/commands/api/request/graphql.ts ) _
116+ _ See code: [ src/commands/api/request/graphql.ts] ( https://github.com/salesforcecli/plugin-api/blob/1.3.0 /src/commands/api/request/graphql.ts ) _
117117
118- ## ` sf api request rest ENDPOINT `
118+ ## ` sf api request rest [URL] `
119119
120120Make an authenticated HTTP request using the Salesforce REST API.
121121
122122```
123123USAGE
124- $ sf api request rest ENDPOINT -o <value> [--flags-dir <value>] [--api-version <value>] [-i | -S Example:
125- report.xlsx] [-X GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE] [-H key:value...] [--body file]
124+ $ sf api request rest [URL] -o <value> [--flags-dir <value>] [--api-version <value>] [-i | -S Example: report.xlsx]
125+ [-X GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE] [-H key:value...] [-f file] [-b file]
126126
127127ARGUMENTS
128- ENDPOINT Salesforce API endpoint
128+ URL Salesforce API endpoint
129129
130130FLAGS
131131 -H, --header=key:value... HTTP header in "key:value" format.
132132 -S, --stream-to-file=Example: report.xlsx Stream responses to a file.
133- -X, --method=<option> [default: GET] HTTP method for the request.
133+ -X, --method=<option> HTTP method for the request.
134134 <options: GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE>
135+ -b, --body=file File or content for the body of the HTTP request. Specify "-" to read from
136+ standard input or "" for an empty body.
137+ -f, --file=file JSON file that contains values for the request header, body, method, and
138+ URL.
135139 -i, --include Include the HTTP response status and headers in the output.
136140 -o, --target-org=<value> (required) Username or alias of the target org. Not required if the
137141 `target-org` configuration variable is already set.
138142 --api-version=<value> Override the api version used for api requests made by this command
139- --body=file File or content for the body of the HTTP request. Specify "-" to read from
140- standard input or "" for an empty body.
141143
142144GLOBAL FLAGS
143145 --flags-dir=<value> Import flag values from a directory.
@@ -167,7 +169,7 @@ EXAMPLES
167169
168170 Create an account record using the POST method; specify the request details directly in the "--body" flag:
169171
170- $ sf api request rest ' sobjects/account' --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \
172+ $ sf api request rest sobjects/account --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \
171173 \"Boise\"}" --method POST
172174
173175 Create an account record using the information in a file called "info.json":
@@ -178,9 +180,49 @@ EXAMPLES
178180
179181 $ sf api request rest 'sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method \
180182 PATCH
183+
184+ Store the values for the request header, body, and so on, in a file, which you then specify with the --file flag;
185+ see the description of --file for more information:
186+
187+ $ sf api request rest --file myFile.json
188+
189+ FLAG DESCRIPTIONS
190+ -f, --file=file JSON file that contains values for the request header, body, method, and URL.
191+
192+ Use this flag instead of specifying the request details with individual flags, such as --body or --method. This
193+ schema defines how to create the JSON file:
194+
195+ {
196+ url: { raw: string } | string;
197+ method: 'GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE';
198+ description?: string;
199+ header: string | Array<Record<string, string>>;
200+ body: { mode: 'raw' | 'formdata'; raw: string; formdata: FormData };
201+ }
202+
203+ Salesforce CLI defined this schema to be mimic Postman schemas; both share similar properties. The CLI's schema also
204+ supports Postman Collections to reuse and share requests. As a result, you can build an API call using Postman,
205+ export and save it to a file, and then use the file as a value to this flag. For information about Postman, see
206+ https://learning.postman.com/.
207+
208+ Here's a simple example of a JSON file that contains values for the request URL, method, and body:
209+
210+ {
211+ "url": "sobjects/Account/<Account ID>",
212+ "method": "PATCH",
213+ "body" : {
214+ "mode": "raw",
215+ "raw": {
216+ "BillingCity": "Boise"
217+ }
218+ }
219+ }
220+
221+ See more examples in the plugin-api test directory, including JSON files that use "formdata" to define collections:
222+ https://github.com/salesforcecli/plugin-api/tree/main/test/test-files/data-project.
181223```
182224
183- _ See code: [ src/commands/api/request/rest.ts] ( https://github.com/salesforcecli/plugin-api/blob/1.2.2 /src/commands/api/request/rest.ts ) _
225+ _ See code: [ src/commands/api/request/rest.ts] ( https://github.com/salesforcecli/plugin-api/blob/1.3.0 /src/commands/api/request/rest.ts ) _
184226
185227<!-- commandsstop -->
186228
0 commit comments