@salesforce/plugin-api 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -52
- package/lib/commands/api/request/rest.d.ts +42 -2
- package/lib/commands/api/request/rest.js +96 -20
- package/lib/commands/api/request/rest.js.map +1 -1
- package/lib/shared/shared.d.ts +0 -2
- package/lib/shared/shared.js +0 -14
- package/lib/shared/shared.js.map +1 -1
- package/messages/graphql.md +12 -25
- package/messages/rest.md +53 -15
- package/oclif.manifest.json +32 -12
- package/package.json +10 -6
- package/npm-shrinkwrap.json +0 -13362
- package/oclif.lock +0 -7529
package/messages/rest.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# summary
|
|
2
2
|
|
|
3
|
-
Make an authenticated HTTP request
|
|
3
|
+
Make an authenticated HTTP request using the Salesforce REST API.
|
|
4
|
+
|
|
5
|
+
# description
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
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.
|
|
4
10
|
|
|
5
11
|
# examples
|
|
6
12
|
|
|
@@ -8,39 +14,71 @@ Make an authenticated HTTP request to Salesforce REST API and print the response
|
|
|
8
14
|
|
|
9
15
|
<%= config.bin %> <%= command.id %> 'limits' --target-org my-org
|
|
10
16
|
|
|
11
|
-
- List all endpoints
|
|
17
|
+
- List all endpoints in your default org; write the output to a file called "output.txt" and include the HTTP response status and headers:
|
|
12
18
|
|
|
13
|
-
<%= config.bin %> <%= command.id %> '/'
|
|
19
|
+
<%= config.bin %> <%= command.id %> '/' --stream-to-file output.txt --include
|
|
14
20
|
|
|
15
21
|
- Get the response in XML format by specifying the "Accept" HTTP header:
|
|
16
22
|
|
|
17
|
-
<%= config.bin %> <%= command.id %> 'limits' --
|
|
18
|
-
|
|
19
|
-
- POST to create an Account object
|
|
23
|
+
<%= config.bin %> <%= command.id %> 'limits' --header 'Accept: application/xml'
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
- Create an account record using the POST method; specify the request details directly in the "--body" flag:
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
<%= config.bin %> <%= command.id %> sobjects/account --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \"Boise\"}" --method POST
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
"Name": "Demo",
|
|
27
|
-
"ShippingCity": "Boise"
|
|
28
|
-
}
|
|
29
|
+
- Create an account record using the information in a file called "info.json":
|
|
29
30
|
|
|
30
|
-
<%= config.bin %> <%= command.id %> 'sobjects/account' --body info.json --method POST
|
|
31
|
+
<%= config.bin %> <%= command.id %> 'sobjects/account' --body info.json --method POST
|
|
31
32
|
|
|
32
|
-
- Update
|
|
33
|
+
- Update an account record using the PATCH method:
|
|
33
34
|
|
|
34
35
|
<%= config.bin %> <%= command.id %> 'sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method PATCH
|
|
35
36
|
|
|
37
|
+
- 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:
|
|
38
|
+
|
|
39
|
+
<%= config.bin %> <%= command.id %> --file myFile.json
|
|
40
|
+
|
|
36
41
|
# flags.method.summary
|
|
37
42
|
|
|
38
43
|
HTTP method for the request.
|
|
39
44
|
|
|
45
|
+
# flags.file.summary
|
|
46
|
+
|
|
47
|
+
JSON file that contains values for the request header, body, method, and URL.
|
|
48
|
+
|
|
49
|
+
# flags.file.description
|
|
50
|
+
|
|
51
|
+
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:
|
|
52
|
+
|
|
53
|
+
{
|
|
54
|
+
url: { raw: string } | string;
|
|
55
|
+
method: 'GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE';
|
|
56
|
+
description?: string;
|
|
57
|
+
header: string | Array<Record<string, string>>;
|
|
58
|
+
body: { mode: 'raw' | 'formdata'; raw: string; formdata: FormData };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
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/.
|
|
62
|
+
|
|
63
|
+
Here's a simple example of a JSON file that contains values for the request URL, method, and body:
|
|
64
|
+
|
|
65
|
+
{
|
|
66
|
+
"url": "sobjects/Account/<Account ID>",
|
|
67
|
+
"method": "PATCH",
|
|
68
|
+
"body" : {
|
|
69
|
+
"mode": "raw",
|
|
70
|
+
"raw": {
|
|
71
|
+
"BillingCity": "Boise"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
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.
|
|
77
|
+
|
|
40
78
|
# flags.header.summary
|
|
41
79
|
|
|
42
80
|
HTTP header in "key:value" format.
|
|
43
81
|
|
|
44
82
|
# flags.body.summary
|
|
45
83
|
|
|
46
|
-
File
|
|
84
|
+
File or content for the body of the HTTP request. Specify "-" to read from standard input or "" for an empty body.
|
package/oclif.manifest.json
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
"api:request:graphql": {
|
|
4
4
|
"aliases": [],
|
|
5
5
|
"args": {},
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "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.\n\nThis 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.",
|
|
7
7
|
"examples": [
|
|
8
|
-
"
|
|
8
|
+
"Execute a GraphQL query on the Account object by specifying the query directly to the \"--body\" flag; the command uses your default org:\n<%= config.bin %> <%= command.id %> --body \"query accounts { uiapi { query { Account { edges { node { Id \\n Name { value } } } } } } }\"",
|
|
9
|
+
"Read the GraphQL statement from a file called \"example.txt\" and execute it on an org with alias \"my-org\":\n<%= config.bin %> <%= command.id %> --body example.txt --target-org my-org",
|
|
10
|
+
"Pipe the GraphQL statement that you want to execute from standard input to the command:\n$ echo graphql | sf api request graphql --body -",
|
|
11
|
+
"Write the output of the command to a file called \"output.txt\" and include the HTTP response status and headers:\n<%= config.bin %> <%= command.id %> --body example.txt --stream-to-file output.txt --include"
|
|
9
12
|
],
|
|
10
13
|
"flags": {
|
|
11
14
|
"json": {
|
|
@@ -65,7 +68,7 @@
|
|
|
65
68
|
"body": {
|
|
66
69
|
"name": "body",
|
|
67
70
|
"required": true,
|
|
68
|
-
"summary": "File or content with GraphQL statement. Specify \"-\" to read from standard input.",
|
|
71
|
+
"summary": "File or content with the GraphQL statement. Specify \"-\" to read from standard input.",
|
|
69
72
|
"hasDynamicHelp": false,
|
|
70
73
|
"helpValue": "file",
|
|
71
74
|
"multiple": false,
|
|
@@ -80,7 +83,7 @@
|
|
|
80
83
|
"pluginType": "core",
|
|
81
84
|
"state": "beta",
|
|
82
85
|
"strict": true,
|
|
83
|
-
"summary": "Execute GraphQL
|
|
86
|
+
"summary": "Execute a GraphQL statement.",
|
|
84
87
|
"enableJsonFlag": true,
|
|
85
88
|
"isESM": true,
|
|
86
89
|
"relativePath": [
|
|
@@ -103,14 +106,21 @@
|
|
|
103
106
|
"api:request:rest": {
|
|
104
107
|
"aliases": [],
|
|
105
108
|
"args": {
|
|
106
|
-
"
|
|
109
|
+
"url": {
|
|
107
110
|
"description": "Salesforce API endpoint",
|
|
108
|
-
"name": "
|
|
109
|
-
"required":
|
|
111
|
+
"name": "url",
|
|
112
|
+
"required": false
|
|
110
113
|
}
|
|
111
114
|
},
|
|
115
|
+
"description": "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.\n\nFor 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.",
|
|
112
116
|
"examples": [
|
|
113
|
-
"
|
|
117
|
+
"List information about limits in the org with alias \"my-org\":\n<%= config.bin %> <%= command.id %> 'limits' --target-org my-org",
|
|
118
|
+
"List all endpoints in your default org; write the output to a file called \"output.txt\" and include the HTTP response status and headers:\n<%= config.bin %> <%= command.id %> '/' --stream-to-file output.txt --include",
|
|
119
|
+
"Get the response in XML format by specifying the \"Accept\" HTTP header:\n<%= config.bin %> <%= command.id %> 'limits' --header 'Accept: application/xml'",
|
|
120
|
+
"Create an account record using the POST method; specify the request details directly in the \"--body\" flag:\n<%= config.bin %> <%= command.id %> sobjects/account --body \"{\\\"Name\\\" : \\\"Account from REST API\\\",\\\"ShippingCity\\\" : \\\"Boise\\\"}\" --method POST",
|
|
121
|
+
"Create an account record using the information in a file called \"info.json\":\n<%= config.bin %> <%= command.id %> 'sobjects/account' --body info.json --method POST",
|
|
122
|
+
"Update an account record using the PATCH method:\n<%= config.bin %> <%= command.id %> 'sobjects/account/<Account ID>' --body \"{\\\"BillingCity\\\": \\\"San Francisco\\\"}\" --method PATCH",
|
|
123
|
+
"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:\n<%= config.bin %> <%= command.id %> --file myFile.json"
|
|
114
124
|
],
|
|
115
125
|
"flags": {
|
|
116
126
|
"flags-dir": {
|
|
@@ -152,7 +162,6 @@
|
|
|
152
162
|
"char": "X",
|
|
153
163
|
"name": "method",
|
|
154
164
|
"summary": "HTTP method for the request.",
|
|
155
|
-
"default": "GET",
|
|
156
165
|
"hasDynamicHelp": false,
|
|
157
166
|
"multiple": false,
|
|
158
167
|
"options": [
|
|
@@ -176,6 +185,16 @@
|
|
|
176
185
|
"multiple": true,
|
|
177
186
|
"type": "option"
|
|
178
187
|
},
|
|
188
|
+
"file": {
|
|
189
|
+
"char": "f",
|
|
190
|
+
"description": "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:\n\n{\nurl: { raw: string } | string;\nmethod: 'GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE';\ndescription?: string;\nheader: string | Array<Record<string, string>>;\nbody: { mode: 'raw' | 'formdata'; raw: string; formdata: FormData };\n}\n\nSalesforce 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/.\n\nHere's a simple example of a JSON file that contains values for the request URL, method, and body:\n\n{\n\"url\": \"sobjects/Account/<Account ID>\",\n\"method\": \"PATCH\",\n\"body\" : {\n\"mode\": \"raw\",\n\"raw\": {\n\"BillingCity\": \"Boise\"\n}\n}\n}\n\nSee 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.",
|
|
191
|
+
"name": "file",
|
|
192
|
+
"summary": "JSON file that contains values for the request header, body, method, and URL.",
|
|
193
|
+
"hasDynamicHelp": false,
|
|
194
|
+
"helpValue": "file",
|
|
195
|
+
"multiple": false,
|
|
196
|
+
"type": "option"
|
|
197
|
+
},
|
|
179
198
|
"stream-to-file": {
|
|
180
199
|
"char": "S",
|
|
181
200
|
"exclusive": [
|
|
@@ -189,8 +208,9 @@
|
|
|
189
208
|
"type": "option"
|
|
190
209
|
},
|
|
191
210
|
"body": {
|
|
211
|
+
"char": "b",
|
|
192
212
|
"name": "body",
|
|
193
|
-
"summary": "File
|
|
213
|
+
"summary": "File or content for the body of the HTTP request. Specify \"-\" to read from standard input or \"\" for an empty body.",
|
|
194
214
|
"hasDynamicHelp": false,
|
|
195
215
|
"helpValue": "file",
|
|
196
216
|
"multiple": false,
|
|
@@ -205,7 +225,7 @@
|
|
|
205
225
|
"pluginType": "core",
|
|
206
226
|
"state": "beta",
|
|
207
227
|
"strict": true,
|
|
208
|
-
"summary": "Make an authenticated HTTP request
|
|
228
|
+
"summary": "Make an authenticated HTTP request using the Salesforce REST API.",
|
|
209
229
|
"enableJsonFlag": false,
|
|
210
230
|
"isESM": true,
|
|
211
231
|
"relativePath": [
|
|
@@ -226,5 +246,5 @@
|
|
|
226
246
|
]
|
|
227
247
|
}
|
|
228
248
|
},
|
|
229
|
-
"version": "1.
|
|
249
|
+
"version": "1.3.0"
|
|
230
250
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/plugin-api",
|
|
3
3
|
"description": "A plugin to call API endpoints via CLI commands",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/forcedotcom/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"@salesforce/sf-plugins-core": "^11.3.2",
|
|
12
12
|
"@salesforce/ts-types": "^2.0.12",
|
|
13
13
|
"ansis": "^3.3.2",
|
|
14
|
+
"form-data": "^4.0.0",
|
|
14
15
|
"got": "^13.0.0",
|
|
15
16
|
"proxy-agent": "^6.4.0"
|
|
16
17
|
},
|
|
@@ -31,8 +32,6 @@
|
|
|
31
32
|
"files": [
|
|
32
33
|
"/lib",
|
|
33
34
|
"/messages",
|
|
34
|
-
"/npm-shrinkwrap.json",
|
|
35
|
-
"/oclif.lock",
|
|
36
35
|
"/oclif.manifest.json",
|
|
37
36
|
"/schemas"
|
|
38
37
|
],
|
|
@@ -58,7 +57,12 @@
|
|
|
58
57
|
],
|
|
59
58
|
"topics": {
|
|
60
59
|
"api": {
|
|
61
|
-
"description": "
|
|
60
|
+
"description": "Commands to interact with API calls.",
|
|
61
|
+
"subtopics": {
|
|
62
|
+
"request": {
|
|
63
|
+
"description": "Commands that make API requests."
|
|
64
|
+
}
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
},
|
|
64
68
|
"flexibleTaxonomy": true
|
|
@@ -202,7 +206,7 @@
|
|
|
202
206
|
"exports": "./lib/index.js",
|
|
203
207
|
"type": "module",
|
|
204
208
|
"sfdx": {
|
|
205
|
-
"publicKeyUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-api/1.
|
|
206
|
-
"signatureUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-api/1.
|
|
209
|
+
"publicKeyUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-api/1.3.0.crt",
|
|
210
|
+
"signatureUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-api/1.3.0.sig"
|
|
207
211
|
}
|
|
208
212
|
}
|