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

ย
๐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.
ย
๐ข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.โ โ โ
โ Please do note that this feature is still in beta, so use wisely!!
๐Do Check Salesforce Documentation on api request rest (Beta)
This Content was originally posted in linkedin View Post