Skip to content

salesforcecli/plugin-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Install

sf plugins install @salesforce/plugin-api

Issues

Please report any issues at https://github.com/forcedotcom/cli/issues

Contributing

  1. Please read our Code of Conduct
  2. Create a new issue before starting your project so that we can keep track of what you are trying to add/fix. That way, we can also offer suggestions or let you know if there is already an effort in progress.
  3. Fork this repository.
  4. Build the plugin locally
  5. Create a topic branch in your fork. Note, this step is recommended but technically not required if contributing using a fork.
  6. Edit the code in your fork.
  7. Write appropriate tests for your changes. Try to achieve at least 95% code coverage on any new code. No pull request will be accepted without unit tests.
  8. Sign CLA (see CLA below).
  9. Send us a pull request when you are done. We'll review your code, suggest any needed changes, and merge it in.

CLA

External contributors will be required to sign a Contributor's License Agreement. You can do so by going to https://cla.salesforce.com/sign-cla.

Build

To build the plugin locally, make sure to have yarn installed and run the following commands:

# Clone the repository
git clone [email protected]:salesforcecli/plugin-template-sf

# Install the dependencies and compile
yarn && yarn build

To use your plugin, run using the local ./bin/dev or ./bin/dev.cmd file.

# Run using local run file.
./bin/dev hello world

There should be no differences when running via the Salesforce CLI or using the local run file. However, it can be useful to link the plugin to do some additional testing or run your commands from anywhere on your machine.

# Link your plugin to the sf cli
sf plugins link .
# To verify
sf plugins

Commands

sf api request graphql

Execute a GraphQL statement.

USAGE
  $ sf api request graphql -o <value> --body file [--json] [--flags-dir <value>] [--api-version <value>] [-S Example:
    report.xlsx | -i]

FLAGS
  -S, --stream-to-file=Example: report.xlsx  Stream responses to a file.
  -i, --include                              Include the HTTP response status and headers in the output.
  -o, --target-org=<value>                   (required) Username or alias of the target org. Not required if the
                                             `target-org` configuration variable is already set.
      --api-version=<value>                  Override the api version used for api requests made by this command
      --body=file                            (required) File or content with the GraphQL statement. Specify "-" to read
                                             from standard input.

GLOBAL FLAGS
  --flags-dir=<value>  Import flag values from a directory.
  --json               Format output as json.

DESCRIPTION
  Execute a GraphQL statement.

  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.

  This 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.

EXAMPLES
  Execute a GraphQL query on the Account object by specifying the query directly to the "--body" flag; the command
  uses your default org:

    $ sf api request graphql --body "query accounts { uiapi { query { Account { edges { node { Id \n Name { value } \
      } } } } } }"

  Read the GraphQL statement from a file called "example.txt" and execute it on an org with alias "my-org":

    $ sf api request graphql --body example.txt --target-org my-org

  Pipe the GraphQL statement that you want to execute from standard input to the command:
  $ echo graphql | sf api request graphql --body -

  Write the output of the command to a file called "output.txt" and include the HTTP response status and headers:

    $ sf api request graphql --body example.txt --stream-to-file output.txt --include

See code: src/commands/api/request/graphql.ts

sf api request rest ENDPOINT

Make an authenticated HTTP request using the Salesforce REST API.

USAGE
  $ sf api request rest ENDPOINT -o <value> [--flags-dir <value>] [--api-version <value>] [-i | -S Example:
    report.xlsx] [-X GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE] [-H key:value...] [--body file]

ARGUMENTS
  ENDPOINT  Salesforce API endpoint

FLAGS
  -H, --header=key:value...                  HTTP header in "key:value" format.
  -S, --stream-to-file=Example: report.xlsx  Stream responses to a file.
  -X, --method=<option>                      [default: GET] HTTP method for the request.
                                             <options: GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE>
  -i, --include                              Include the HTTP response status and headers in the output.
  -o, --target-org=<value>                   (required) Username or alias of the target org. Not required if the
                                             `target-org` configuration variable is already set.
      --api-version=<value>                  Override the api version used for api requests made by this command
      --body=file                            File or content for the body of the HTTP request. Specify "-" to read from
                                             standard input or "" for an empty body.

GLOBAL FLAGS
  --flags-dir=<value>  Import flag values from a directory.

DESCRIPTION
  Make an authenticated HTTP request using the Salesforce REST API.

  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.

  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.

EXAMPLES
  List information about limits in the org with alias "my-org":

    $ sf api request rest 'limits' --target-org my-org

  List all endpoints in your default org; write the output to a file called "output.txt" and include the HTTP response
  status and headers:

    $ sf api request rest '/' --stream-to-file output.txt --include

  Get the response in XML format by specifying the "Accept" HTTP header:

    $ sf api request rest 'limits' --header 'Accept: application/xml'

  Create an account record using the POST method; specify the request details directly in the "--body" flag:

    $ sf api request rest 'sobjects/account' --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \
      \"Boise\"}" --method POST

  Create an account record using the information in a file called "info.json":

    $ sf api request rest 'sobjects/account' --body info.json --method POST

  Update an account record using the PATCH method:

    $ sf api request rest 'sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method \
      PATCH

See code: src/commands/api/request/rest.ts