|
1 |
| -**NOTE: This template for sf plugins is not yet official. Please consult with the Platform CLI team before using this template.** |
2 |
| - |
3 |
| -# plugin-template-sf |
4 |
| - |
5 |
| -[](https://www.npmjs.com/package/@salesforce/plugin-template-sf) [](https://npmjs.org/package/@salesforce/plugin-template-sf) [](https://raw.githubusercontent.com/salesforcecli/plugin-template-sf/main/LICENSE.txt) |
6 |
| - |
7 |
| -## Using the template |
8 |
| - |
9 |
| -This repository provides a template for creating a plugin for the Salesforce CLI. To convert this template to a working plugin: |
10 |
| - |
11 |
| -1. Please get in touch with the Platform CLI team. We want to help you develop your plugin. |
12 |
| -2. Generate your plugin: |
13 |
| - |
14 |
| - ``` |
15 |
| - sf plugins install dev |
16 |
| - sf dev generate plugin |
17 |
| -
|
18 |
| - git init -b main |
19 |
| - git add . && git commit -m "chore: initial commit" |
20 |
| - ``` |
21 |
| - |
22 |
| -3. Create your plugin's repo in the salesforcecli github org |
23 |
| -4. When you're ready, replace the contents of this README with the information you want. |
24 |
| - |
25 |
| -## Learn about `sf` plugins |
26 |
| - |
27 |
| -Salesforce CLI plugins are based on the [oclif plugin framework](https://oclif.io/docs/introduction). Read the [plugin developer guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_plugins.meta/sfdx_cli_plugins/cli_plugins_architecture_sf_cli.htm) to learn about Salesforce CLI plugin development. |
28 |
| - |
29 |
| -This repository contains a lot of additional scripts and tools to help with general Salesforce node development and enforce coding standards. You should familiarize yourself with some of the [node developer packages](#tooling) used by Salesforce. There is also a default circleci config using the [release management orb](https://github.com/forcedotcom/npm-release-management-orb) standards. |
30 |
| - |
31 |
| -Additionally, there are some additional tests that the Salesforce CLI will enforce if this plugin is ever bundled with the CLI. These test are included by default under the `posttest` script and it is required to keep these tests active in your plugin if you plan to have it bundled. |
32 |
| - |
33 |
| -### Tooling |
34 |
| - |
35 |
| -- [@salesforce/core](https://github.com/forcedotcom/sfdx-core) |
36 |
| -- [@salesforce/kit](https://github.com/forcedotcom/kit) |
37 |
| -- [@salesforce/sf-plugins-core](https://github.com/salesforcecli/sf-plugins-core) |
38 |
| -- [@salesforce/ts-types](https://github.com/forcedotcom/ts-types) |
39 |
| -- [@salesforce/ts-sinon](https://github.com/forcedotcom/ts-sinon) |
40 |
| -- [@salesforce/dev-config](https://github.com/forcedotcom/dev-config) |
41 |
| -- [@salesforce/dev-scripts](https://github.com/forcedotcom/dev-scripts) |
42 |
| - |
43 |
| -# Everything past here is only a suggestion as to what should be in your specific plugin's description |
44 |
| - |
45 |
| -This plugin is bundled with the [Salesforce CLI](https://developer.salesforce.com/tools/sfdxcli). For more information on the CLI, read the [getting started guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm). |
46 |
| - |
47 |
| -We always recommend using the latest version of these commands bundled with the CLI, however, you can install a specific version or tag if needed. |
48 |
| - |
49 | 1 | ## Install
|
50 | 2 |
|
51 | 3 | ```bash
|
52 |
| -sf plugins install @salesforce/plugin-template-sf@x.y.z |
| 4 | +sf plugins install @salesforce/plugin-api |
53 | 5 | ```
|
54 | 6 |
|
55 | 7 | ## Issues
|
@@ -107,59 +59,119 @@ sf plugins
|
107 | 59 |
|
108 | 60 | <!-- commands -->
|
109 | 61 |
|
| 62 | +- [`sf api request graphql`](#sf-api-request-graphql) |
110 | 63 | - [`sf api request rest ENDPOINT`](#sf-api-request-rest-endpoint)
|
111 | 64 |
|
112 |
| -## `sf api request rest ENDPOINT` |
| 65 | +## `sf api request graphql` |
113 | 66 |
|
114 |
| -Make an authenticated HTTP request to Salesforce REST API and print the response. |
| 67 | +Execute GraphQL statements |
115 | 68 |
|
116 | 69 | ````
|
117 | 70 | USAGE
|
118 |
| - $ sf api request rest ENDPOINT -o <value> [--flags-dir <value>] [--api-version <value>] [-i | -S Example: |
119 |
| - report.xlsx] [-X GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE] [-H key:value...] [--body file] |
120 |
| -
|
121 |
| -ARGUMENTS |
122 |
| - ENDPOINT Salesforce API endpoint |
| 71 | + $ sf api request graphql -o <value> --body file [--json] [--flags-dir <value>] [-S Example: report.xlsx | -i] |
123 | 72 |
|
124 | 73 | FLAGS
|
125 |
| - -H, --header=key:value... HTTP header in "key:value" format. |
126 | 74 | -S, --stream-to-file=Example: report.xlsx Stream responses to a file.
|
127 |
| - -X, --method=<option> [default: GET] HTTP method for the request. |
128 |
| - <options: GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE> |
129 | 75 | -i, --include Include the HTTP response status and headers in the output.
|
130 | 76 | -o, --target-org=<value> (required) Username or alias of the target org. Not required if the
|
131 | 77 | `target-org` configuration variable is already set.
|
132 |
| - --api-version=<value> Override the api version used for api requests made by this command |
133 |
| - --body=file File to use as the body for the request. Specify "-" to read from standard |
134 |
| - input; specify "" for an empty body. |
| 78 | + --body=file (required) File or content with GraphQL statement. Specify "-" to read from |
| 79 | + standard input. |
135 | 80 |
|
136 | 81 | GLOBAL FLAGS
|
137 | 82 | --flags-dir=<value> Import flag values from a directory.
|
| 83 | + --json Format output as json. |
| 84 | +
|
| 85 | +DESCRIPTION |
| 86 | + Execute GraphQL statements |
| 87 | +
|
| 88 | + Run any valid GraphQL statement via the /graphql |
| 89 | + [API](https://developer.salesforce.com/docs/platform/graphql/guide/graphql-about.html) |
138 | 90 |
|
139 | 91 | EXAMPLES
|
140 |
| - - List information about limits in the org with alias "my-org": |
141 |
| - sf api request rest 'limits' --target-org my-org |
142 |
| - - List all endpoints |
143 |
| - sf api request rest '/' |
144 |
| - - Get the response in XML format by specifying the "Accept" HTTP header: |
145 |
| - sf api request rest 'limits' --target-org my-org --header 'Accept: application/xml' |
146 |
| - - POST to create an Account object |
147 |
| - sf api request rest 'sobjects/account' --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \"Boise\"}" --method POST |
148 |
| - - or with a file 'info.json' containing |
149 |
| - ```json |
150 |
| - { |
151 |
| - "Name": "Demo", |
152 |
| - "ShippingCity": "Boise" |
| 92 | + - Runs the graphql query directly via the command line |
| 93 | + sf api request graphql --body '{ "query": "query accounts { uiapi { query { Account { edges { node { Id \n Name { value } } } } } } }" }' |
| 94 | + - Runs a mutation to create an Account, with an `example.txt` file, containing |
| 95 | + ```text |
| 96 | + mutation AccountExample{ |
| 97 | + uiapi { |
| 98 | + AccountCreate(input: { |
| 99 | + Account: { |
| 100 | + Name: "Trailblazer Express" |
| 101 | + } |
| 102 | + }) { |
| 103 | + Record { |
| 104 | + Id |
| 105 | + Name { |
| 106 | + value |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + } |
153 | 111 | }
|
154 | 112 | ````
|
155 | 113 |
|
| 114 | +$ sf api request graphql --body example.txt |
| 115 | +will create a new account returning specified fields (Id, Name) |
| 116 | + |
| 117 | +``` |
| 118 | +
|
| 119 | +_See code: [src/commands/api/request/graphql.ts](https://github.com/salesforcecli/plugin-api/blob/v1.1.0/src/commands/api/request/graphql.ts)_ |
| 120 | +
|
| 121 | +## `sf api request rest ENDPOINT` |
| 122 | +
|
| 123 | +Make an authenticated HTTP request to Salesforce REST API and print the response. |
| 124 | +
|
| 125 | +``` |
| 126 | + |
| 127 | +USAGE |
| 128 | +$ sf api request rest ENDPOINT -o <value> [--flags-dir <value>] [--api-version <value>] [-i | -S Example: |
| 129 | +report.xlsx] [-X GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE] [-H key:value...] [--body file] |
| 130 | + |
| 131 | +ARGUMENTS |
| 132 | +ENDPOINT Salesforce API endpoint |
| 133 | + |
| 134 | +FLAGS |
| 135 | +-H, --header=key:value... HTTP header in "key:value" format. |
| 136 | +-S, --stream-to-file=Example: report.xlsx Stream responses to a file. |
| 137 | +-X, --method=<option> [default: GET] HTTP method for the request. |
| 138 | +<options: GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE> |
| 139 | +-i, --include Include the HTTP response status and headers in the output. |
| 140 | +-o, --target-org=<value> (required) Username or alias of the target org. Not required if the |
| 141 | +`target-org` configuration variable is already set. |
| 142 | +--api-version=<value> Override the api version used for api requests made by this command |
| 143 | +--body=file File to use as the body for the request. Specify "-" to read from standard |
| 144 | +input; specify "" for an empty body. |
| 145 | + |
| 146 | +GLOBAL FLAGS |
| 147 | +--flags-dir=<value> Import flag values from a directory. |
| 148 | + |
| 149 | +EXAMPLES |
| 150 | + |
| 151 | +- List information about limits in the org with alias "my-org": |
| 152 | + sf api request rest 'limits' --target-org my-org |
| 153 | +- List all endpoints |
| 154 | + sf api request rest '/' |
| 155 | +- Get the response in XML format by specifying the "Accept" HTTP header: |
| 156 | + sf api request rest 'limits' --target-org my-org --header 'Accept: application/xml' |
| 157 | +- POST to create an Account object |
| 158 | + sf api request rest 'sobjects/account' --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \"Boise\"}" --method POST |
| 159 | +- or with a file 'info.json' containing |
| 160 | + |
| 161 | +```json |
| 162 | +{ |
| 163 | + "Name": "Demo", |
| 164 | + "ShippingCity": "Boise" |
| 165 | +} |
| 166 | +``` |
| 167 | + |
156 | 168 | $ sf api request rest 'sobjects/account' --body info.json --method POST
|
157 | 169 |
|
158 | 170 | - Update object
|
159 | 171 | sf api request rest 'sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method PATCH
|
160 | 172 |
|
161 | 173 | ```
|
162 | 174 |
|
163 |
| -_See code: [src/commands/api/request/rest.ts](https://github.com/salesforcecli/plugin-api/blob/0.1.0/src/commands/api/request/rest.ts)_ |
| 175 | +_See code: [src/commands/api/request/rest.ts](https://github.com/salesforcecli/plugin-api/blob/v1.1.0/src/commands/api/request/rest.ts)_ |
164 | 176 | <!-- commandsstop -->
|
165 | 177 | ```
|
0 commit comments