@@ -60,7 +60,7 @@ sf plugins
60
60
<!-- commands -->
61
61
62
62
- [ ` 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 )
64
64
65
65
## ` sf api request graphql `
66
66
@@ -113,31 +113,33 @@ EXAMPLES
113
113
$ sf api request graphql --body example.txt --stream-to-file output.txt --include
114
114
```
115
115
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 ) _
117
117
118
- ## ` sf api request rest ENDPOINT `
118
+ ## ` sf api request rest [URL] `
119
119
120
120
Make an authenticated HTTP request using the Salesforce REST API.
121
121
122
122
```
123
123
USAGE
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]
126
126
127
127
ARGUMENTS
128
- ENDPOINT Salesforce API endpoint
128
+ URL Salesforce API endpoint
129
129
130
130
FLAGS
131
131
-H, --header=key:value... HTTP header in "key:value" format.
132
132
-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.
134
134
<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.
135
139
-i, --include Include the HTTP response status and headers in the output.
136
140
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the
137
141
`target-org` configuration variable is already set.
138
142
--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.
141
143
142
144
GLOBAL FLAGS
143
145
--flags-dir=<value> Import flag values from a directory.
@@ -167,7 +169,7 @@ EXAMPLES
167
169
168
170
Create an account record using the POST method; specify the request details directly in the "--body" flag:
169
171
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\" : \
171
173
\"Boise\"}" --method POST
172
174
173
175
Create an account record using the information in a file called "info.json":
@@ -178,9 +180,49 @@ EXAMPLES
178
180
179
181
$ sf api request rest 'sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method \
180
182
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.
181
223
```
182
224
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 ) _
184
226
185
227
<!-- commandsstop -->
186
228
0 commit comments