Skip to content

Commit 341d2b9

Browse files
committed
chore(release): 1.3.0 [skip ci]
1 parent aef0d4b commit 341d2b9

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# [1.3.0](https://github.com/salesforcecli/plugin-api/compare/1.2.2...1.3.0) (2024-10-03)
2+
3+
### Features
4+
5+
- **rest:** add `--file` request flag ([#14](https://github.com/salesforcecli/plugin-api/issues/14)) ([aef0d4b](https://github.com/salesforcecli/plugin-api/commit/aef0d4b136f29ab5bd46ef4482169c5b13a720a0))
6+
17
## [1.2.2](https://github.com/salesforcecli/plugin-api/compare/1.2.1...1.2.2) (2024-09-19)
28

39
### Bug Fixes

Diff for: README.md

+53-11
Original file line numberDiff line numberDiff line change
@@ -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

120120
Make an authenticated HTTP request using the Salesforce REST API.
121121

122122
```
123123
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]
126126
127127
ARGUMENTS
128-
ENDPOINT Salesforce API endpoint
128+
URL Salesforce API endpoint
129129
130130
FLAGS
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
142144
GLOBAL 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

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/plugin-api",
33
"description": "A plugin to call API endpoints via CLI commands",
4-
"version": "1.2.2",
4+
"version": "1.3.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {

0 commit comments

Comments
 (0)