#
ドキュメント

Document

自分のための備忘録です。

Lightning Platform RESTによるデータ処理

ベースURI

リソースの URI は、認証サービスから取得するベース URI (http://domain/services/data) に続きます。

https://developer.salesforce.com/docs/atlas.ja-jp.api_rest.meta/api_rest/resources_list.htm

↑のdomainOAuth 2.0で返されるinstance_url

以下はアクセストークン取得時のレスポンスとして返されたinstance_url

Postman

s-hiroshi-dev-ed.lightning.force.comを指定してレコードを更新したが失敗した。
↑のOAuth2.0認証でアクエストークンを取得する際に返されるinstance_urlの値s-hiroshi-dev-ed.my.salesforce.com に変更したら正常に更新できた。

  • ドメインは私のドメインで確認できるが、OAuth2.0instance_urlを使うのが安全
  • 私のドメインinstance_urlが常に同じになるかは未確認

https://help.salesforce.com/articleView?id=000322728&type=1&mode=1

  • s-hiroshi-dev-ed.my.salesforce.com ○
  • s-hiroshi-dev-ed.lightning.force.com ×

オブジェクトを取得

例:物件オブジェクト(API参照名 Property__c)のID a0000000000000000Dに関する情報を取得。
(物件はPropertyというらしい)

$ curl --location --request GET 'https://xxx.salesforce.com/services/data/v48.0/sobjects/Property__c/a0000000000000000D' \
--header 'X-PrettyPrint: 1' \
--header 'Authorization: Bearer {{access_token}}'

IDはブラウザで該当物件を表示したときに表示される値。
ref. https://www.synergy-marketing.co.jp/cloud/synergylead/support/salesforceid-output-byreport/

X-PrettyPrint:1については以下を参照。
ref. https://developer.salesforce.com/docs/atlas.ja-jp.api_rest.meta/api_rest/dome_event_log_file_download.htm (Official)

オブジェクトを更新

接続アプリケーションまたはユーザーに対象オブジェクトの書き込み権限があるかを確認。

WordBench

Workbench__REST_Explorer.png

cURL

{{domain}}は私のドメインで確認する。

  • -X--requestの短縮形
  • -L--locationの短縮形
  • -D--dump-headerの短縮形

例1

curl --location --request PATCH 'https://{{domain}}/services/data/v52.0/sobjects/Account/{{object id}}' \
--header 'Content-Type: application/json; charset=UTF-8' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{access_token}}' \
-d '{"Name": "San4"}'

例2

curl --location --request PATCH 'https://{{domain}}/services/data/v52.0/sobjects/Account/{{object id}}' \
--header 'Content-Type: application/json; charset=UTF-8' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{access_token}}' \
--data-raw '{
    "Name": "San2"
}'

例3

  • -D -で標準出力にレスポンスヘッダ表示
  • -d "@salesforce.json"でローカルの同一ディレクトリにあるsalesforce.jsonの値で更新
 curl -D - -X PATCH 'https://{{domain}}/services/data/v52.0/sobjects/Account/{{object id}}' \
--header 'Content-Type: application/json; charset=UTF-8' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer  {{access_token}}' \
-d "@salesforce.json"

Postmanを使用

Explore the Salesforce APIs with a Postman Collection