Quick Tip! Make An Authenticated HTTP Request using Salesforce CLI ๐Ÿš€

ย 

๐ŸŸขYou can use '๐˜ด๐˜ง ๐˜ข๐˜ฑ๐˜ช ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ณ๐˜ฆ๐˜ด๐˜ต' command to make an api callout to your salesforce org using salesforce cli. Image 1 ย  Image 2


๐ŸŸขFor quick start here are some examples:

  • ๐Ÿ‘‰List information about limits in the org with alias “my-org”:

๐˜ด๐˜ง ๐˜ข๐˜ฑ๐˜ช ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ณ๐˜ฆ๐˜ด๐˜ต '๐˜ด๐˜ฆ๐˜ณ๐˜ท๐˜ช๐˜ค๐˜ฆ๐˜ด/๐˜ฅ๐˜ข๐˜ต๐˜ข/๐˜ท56.0/๐˜ญ๐˜ช๐˜ฎ๐˜ช๐˜ต๐˜ด' --๐˜ต๐˜ข๐˜ณ๐˜จ๐˜ฆ๐˜ต-๐˜ฐ๐˜ณ๐˜จ ๐˜ฎ๐˜บ-๐˜ฐ๐˜ณ๐˜จ

  • ๐Ÿ‘‰List all endpoints in your default org; write the output to a file called “output.txt” and include the HTTP response status and headers:

๐˜ด๐˜ง ๐˜ข๐˜ฑ๐˜ช ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ณ๐˜ฆ๐˜ด๐˜ต '/๐˜ด๐˜ฆ๐˜ณ๐˜ท๐˜ช๐˜ค๐˜ฆ๐˜ด/๐˜ฅ๐˜ข๐˜ต๐˜ข/๐˜ท56.0/' --๐˜ด๐˜ต๐˜ณ๐˜ฆ๐˜ข๐˜ฎ-๐˜ต๐˜ฐ-๐˜ง๐˜ช๐˜ญ๐˜ฆ ๐˜ฐ๐˜ถ๐˜ต๐˜ฑ๐˜ถ๐˜ต.๐˜ต๐˜น๐˜ต --๐˜ช๐˜ฏ๐˜ค๐˜ญ๐˜ถ๐˜ฅ๐˜ฆ

  • ๐Ÿ‘‰Get the response in XML format by specifying the “Accept” HTTP header:

๐˜ด๐˜ง ๐˜ข๐˜ฑ๐˜ช ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ณ๐˜ฆ๐˜ด๐˜ต '/๐˜ด๐˜ฆ๐˜ณ๐˜ท๐˜ช๐˜ค๐˜ฆ๐˜ด/๐˜ฅ๐˜ข๐˜ต๐˜ข/๐˜ท56.0/๐˜ญ๐˜ช๐˜ฎ๐˜ช๐˜ต๐˜ด' --๐˜ฉ๐˜ฆ๐˜ข๐˜ฅ๐˜ฆ๐˜ณ '๐˜ˆ๐˜ค๐˜ค๐˜ฆ๐˜ฑ๐˜ต: ๐˜ข๐˜ฑ๐˜ฑ๐˜ญ๐˜ช๐˜ค๐˜ข๐˜ต๐˜ช๐˜ฐ๐˜ฏ/๐˜น๐˜ฎ๐˜ญ'

  • ๐Ÿ‘‰Create an account record using the POST method; specify the request details directly in the “–body” flag:

๐˜ด๐˜ง ๐˜ข๐˜ฑ๐˜ช ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ณ๐˜ฆ๐˜ด๐˜ต /๐˜ด๐˜ฆ๐˜ณ๐˜ท๐˜ช๐˜ค๐˜ฆ๐˜ด/๐˜ฅ๐˜ข๐˜ต๐˜ข/๐˜ท56.0/๐˜ด๐˜ฐ๐˜ฃ๐˜ซ๐˜ฆ๐˜ค๐˜ต๐˜ด/๐˜ข๐˜ค๐˜ค๐˜ฐ๐˜ถ๐˜ฏ๐˜ต --๐˜ฃ๐˜ฐ๐˜ฅ๐˜บ "{\"๐˜•๐˜ข๐˜ฎ๐˜ฆ\" : \"๐˜ˆ๐˜ค๐˜ค๐˜ฐ๐˜ถ๐˜ฏ๐˜ต ๐˜ง๐˜ณ๐˜ฐ๐˜ฎ ๐˜™๐˜Œ๐˜š๐˜› ๐˜ˆ๐˜—๐˜\",\"๐˜š๐˜ฉ๐˜ช๐˜ฑ๐˜ฑ๐˜ช๐˜ฏ๐˜จ๐˜Š๐˜ช๐˜ต๐˜บ\" : \"๐˜‰๐˜ฐ๐˜ช๐˜ด๐˜ฆ\"}" --๐˜ฎ๐˜ฆ๐˜ต๐˜ฉ๐˜ฐ๐˜ฅ ๐˜—๐˜–๐˜š๐˜›

  • ๐Ÿ‘‰Create an account record using the information in a file called “info.json” (note the @ prefixing the file name):

๐˜ด๐˜ง ๐˜ข๐˜ฑ๐˜ช ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ณ๐˜ฆ๐˜ด๐˜ต '/๐˜ด๐˜ฆ๐˜ณ๐˜ท๐˜ช๐˜ค๐˜ฆ๐˜ด/๐˜ฅ๐˜ข๐˜ต๐˜ข/๐˜ท56.0/๐˜ด๐˜ฐ๐˜ฃ๐˜ซ๐˜ฆ๐˜ค๐˜ต๐˜ด/๐˜ข๐˜ค๐˜ค๐˜ฐ๐˜ถ๐˜ฏ๐˜ต' --๐˜ฃ๐˜ฐ๐˜ฅ๐˜บ @๐˜ช๐˜ฏ๐˜ง๐˜ฐ.๐˜ซ๐˜ด๐˜ฐ๐˜ฏ --๐˜ฎ๐˜ฆ๐˜ต๐˜ฉ๐˜ฐ๐˜ฅ ๐˜—๐˜–๐˜š๐˜›

  • ๐Ÿ‘‰Update an account record using the PATCH method:

๐˜ด๐˜ง ๐˜ข๐˜ฑ๐˜ช ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ณ๐˜ฆ๐˜ด๐˜ต '/๐˜ด๐˜ฆ๐˜ณ๐˜ท๐˜ช๐˜ค๐˜ฆ๐˜ด/๐˜ฅ๐˜ข๐˜ต๐˜ข/๐˜ท56.0/๐˜ด๐˜ฐ๐˜ฃ๐˜ซ๐˜ฆ๐˜ค๐˜ต๐˜ด/๐˜ข๐˜ค๐˜ค๐˜ฐ๐˜ถ๐˜ฏ๐˜ต/<๐˜ˆ๐˜ค๐˜ค๐˜ฐ๐˜ถ๐˜ฏ๐˜ต ๐˜๐˜‹>' --๐˜ฃ๐˜ฐ๐˜ฅ๐˜บ "{\"๐˜‰๐˜ช๐˜ญ๐˜ญ๐˜ช๐˜ฏ๐˜จ๐˜Š๐˜ช๐˜ต๐˜บ\": \"๐˜š๐˜ข๐˜ฏ ๐˜๐˜ณ๐˜ข๐˜ฏ๐˜ค๐˜ช๐˜ด๐˜ค๐˜ฐ\"}" --๐˜ฎ๐˜ฆ๐˜ต๐˜ฉ๐˜ฐ๐˜ฅ ๐˜—๐˜ˆ๐˜›๐˜Š๐˜

๐ŸŸขYou can also store the values for the request header, body, and so on, in a file as below

{
๐˜ถ๐˜ณ๐˜ญ: { ๐˜ณ๐˜ข๐˜ธ: ๐˜ด๐˜ต๐˜ณ๐˜ช๐˜ฏ๐˜จ } | ๐˜ด๐˜ต๐˜ณ๐˜ช๐˜ฏ๐˜จ;
๐˜ฎ๐˜ฆ๐˜ต๐˜ฉ๐˜ฐ๐˜ฅ: '๐˜Ž๐˜Œ๐˜›', '๐˜—๐˜–๐˜š๐˜›', '๐˜—๐˜œ๐˜›', '๐˜—๐˜ˆ๐˜›๐˜Š๐˜', '๐˜๐˜Œ๐˜ˆ๐˜‹', '๐˜‹๐˜Œ๐˜“๐˜Œ๐˜›๐˜Œ', '๐˜–๐˜—๐˜›๐˜๐˜–๐˜•๐˜š', '๐˜›๐˜™๐˜ˆ๐˜Š๐˜Œ';
๐˜ฅ๐˜ฆ๐˜ด๐˜ค๐˜ณ๐˜ช๐˜ฑ๐˜ต๐˜ช๐˜ฐ๐˜ฏ?: ๐˜ด๐˜ต๐˜ณ๐˜ช๐˜ฏ๐˜จ;
๐˜ฉ๐˜ฆ๐˜ข๐˜ฅ๐˜ฆ๐˜ณ: ๐˜ด๐˜ต๐˜ณ๐˜ช๐˜ฏ๐˜จ | ๐˜ˆ๐˜ณ๐˜ณ๐˜ข๐˜บ<๐˜™๐˜ฆ๐˜ค๐˜ฐ๐˜ณ๐˜ฅ<๐˜ด๐˜ต๐˜ณ๐˜ช๐˜ฏ๐˜จ, ๐˜ด๐˜ต๐˜ณ๐˜ช๐˜ฏ๐˜จ>>;
๐˜ฃ๐˜ฐ๐˜ฅ๐˜บ: { ๐˜ฎ๐˜ฐ๐˜ฅ๐˜ฆ: '๐˜ณ๐˜ข๐˜ธ' | '๐˜ง๐˜ฐ๐˜ณ๐˜ฎ๐˜ฅ๐˜ข๐˜ต๐˜ข'; ๐˜ณ๐˜ข๐˜ธ: ๐˜ด๐˜ต๐˜ณ๐˜ช๐˜ฏ๐˜จ; ๐˜ง๐˜ฐ๐˜ณ๐˜ฎ๐˜ฅ๐˜ข๐˜ต๐˜ข: ๐˜๐˜ฐ๐˜ณ๐˜ฎ๐˜‹๐˜ข๐˜ต๐˜ข };
}

and then you then specifythe same in a callout with the –๐˜ง๐˜ช๐˜ญ๐˜ฆ flag.

๐˜ด๐˜ง ๐˜ข๐˜ฑ๐˜ช ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ณ๐˜ฆ๐˜ด๐˜ต --๐˜ง๐˜ช๐˜ญ๐˜ฆ ๐˜ฎ๐˜บ๐˜๐˜ช๐˜ญ๐˜ฆ.๐˜ซ๐˜ด๐˜ฐ๐˜ฏ

Salesforce CLI uses this schema to mimic Postman schemas and both share similar properties. 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.โœ…โœ…โœ…

๐Ÿ”—Do Check Salesforce Documentation on api request rest (Beta)

This Content was originally posted in linkedin View Post