From eacc3165c8d11653bf3cbb70c171426890659829 Mon Sep 17 00:00:00 2001 From: Juliet Shackell Date: Tue, 1 Oct 2024 09:13:47 -0700 Subject: [PATCH 1/2] fix: edit messages --- messages/rest.md | 50 ++++++++++++++++++-------------- src/commands/api/request/rest.ts | 1 + 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/messages/rest.md b/messages/rest.md index 9394e9a..8e609f0 100644 --- a/messages/rest.md +++ b/messages/rest.md @@ -34,36 +34,42 @@ For a full list of supported REST endpoints and resources, see https://developer <%= config.bin %> <%= command.id %> 'sobjects/account/' --body "{\"BillingCity\": \"San Francisco\"}" --method PATCH -- You can store every flag option as a parameter in a json file, with the following schema: - { - url: { raw: string } | string; - method: 'GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'; - description?: string; - header: string | Array>; - body: { mode: 'raw' | 'formdata'; raw: string; formdata: FormData }; - } - - looking at the example above, we could store all of this information in the file, and change the command to +- Rather than specify all the argument and flag values at the command line, store them in a file which you pass to the command; see the description of the --file flag for more information: <%= config.bin %> <%= command.id %> --file myFile.json - where myFile.json contains - { - "url": "sobjects/Account/", - "method": "PATCH", - "body" : {"BillingCity": "Boise"} - } - -- If you work in Postman a lot this schema may look familiar, because it shares as many similar properties as we could. Building an API call in postman then exporting and saving the file and executing via the CLI is now possible. -- - # flags.method.summary HTTP method for the request. # flags.file.summary -A json file to store values for header/body/method/url - this is a similar format as a Postman Collection Format. +JSON file to store values for the header/body/method/url + +# flags.file.description + +You can store every flag option as a parameter in a json file, with the following schema: + +{ +url: { raw: string } | string; +method: 'GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'; +description?: string; +header: string | Array>; +body: { mode: 'raw' | 'formdata'; raw: string; formdata: FormData }; +} + +<%= config.bin %> <%= command.id %> --file myFile.json + +where myFile.json contains +{ +"url": "sobjects/Account/", +"method": "PATCH", +"body" : {"BillingCity": "Boise"} +} + +If you work in Postman a lot this schema may look familiar, because it shares as many similar properties as we could. Building an API call in postman then exporting and saving the file and executing via the CLI is now possible. + +The format of the file is similar to the Postman Collection Format. For example: { "method": "POST", @@ -95,7 +101,7 @@ A json file to store values for header/body/method/url - this is a similar forma "url": "connect/user-profiles/me/photo" } -see more examples in this repo's test directory https://github.com/salesforcecli/plugin-api/tree/main/test/test-files/data-project +See more examples in this repo's test directory https://github.com/salesforcecli/plugin-api/tree/main/test/test-files/data-project. # flags.header.summary diff --git a/src/commands/api/request/rest.ts b/src/commands/api/request/rest.ts index d283a99..f5755e3 100644 --- a/src/commands/api/request/rest.ts +++ b/src/commands/api/request/rest.ts @@ -52,6 +52,7 @@ export class Rest extends SfCommand { }), file: Flags.file({ summary: messages.getMessage('flags.file.summary'), + description: messages.getMessage('flags.file.description'), helpValue: 'file', char: 'f', }), From b4907053ef835825fad19614c7931cec9407e679 Mon Sep 17 00:00:00 2001 From: Juliet Shackell Date: Tue, 1 Oct 2024 09:57:03 -0700 Subject: [PATCH 2/2] fix: more edits --- messages/rest.md | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/messages/rest.md b/messages/rest.md index 8e609f0..c690b28 100644 --- a/messages/rest.md +++ b/messages/rest.md @@ -34,7 +34,7 @@ For a full list of supported REST endpoints and resources, see https://developer <%= config.bin %> <%= command.id %> 'sobjects/account/' --body "{\"BillingCity\": \"San Francisco\"}" --method PATCH -- Rather than specify all the argument and flag values at the command line, store them in a file which you pass to the command; see the description of the --file flag for more information: +- 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: <%= config.bin %> <%= command.id %> --file myFile.json @@ -44,11 +44,11 @@ HTTP method for the request. # flags.file.summary -JSON file to store values for the header/body/method/url +JSON file that contains values for the request header, body, method, and URL. # flags.file.description -You can store every flag option as a parameter in a json file, with the following schema: +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: { url: { raw: string } | string; @@ -58,50 +58,17 @@ header: string | Array>; body: { mode: 'raw' | 'formdata'; raw: string; formdata: FormData }; } -<%= config.bin %> <%= command.id %> --file myFile.json +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/. + +Here's a simple example of a JSON file that contains values for the request URL, method, and body: -where myFile.json contains { "url": "sobjects/Account/", "method": "PATCH", "body" : {"BillingCity": "Boise"} } -If you work in Postman a lot this schema may look familiar, because it shares as many similar properties as we could. Building an API call in postman then exporting and saving the file and executing via the CLI is now possible. - -The format of the file is similar to the Postman Collection Format. For example: - -{ -"method": "POST", -"header": [ -{ -"key": "content-type", -"value": "multipart/form-data" -}, -{ -"key": "Accept", -"value": "application/json" -} -], -"body": { -"mode": "formdata", -"formdata": [ -{ -"key": "json", -"type": "text", -"value": "{\"cropY\":\"0\",\"cropX\":\"0\",\"cropSize\":\"200\"}" -} , -{ -"key": "fileUpload", -"type": "file", -"src": "myImg.jpeg" -} -] -}, -"url": "connect/user-profiles/me/photo" -} - -See more examples in this repo's test directory https://github.com/salesforcecli/plugin-api/tree/main/test/test-files/data-project. +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. # flags.header.summary