はじめに
Salesforceに対して、様々な操作を行えるSalesforce REST APIというものがあります。
Salesforce REST APIはPHPやRubyといったプログラムからだけでなく、cURL(カール)コマンドでも呼び出す事が出来ます。
cURLコマンドを使って、Salesforce REST APIを呼び出して、Force.comカスタムオブジェクトのレコード参照・更新、Force.comカスタムオブジェクトの項目やデータ型の定義を確認したりといった各種操作を行う事が可能です。
cURLコマンドでSalesforce REST APIを呼び出して、各種操作を行う例について記します。
なお、cURLコマンドによるChatter REST APIの操作については、以下の記事をご参照下さい。
cURLコマンドとシェルスクリプトでSalesforce Chatter REST APIを実行してChatterメッセージを投稿する
参考資料
Salesforce REST APIについては、Salesforce社のForce.com REST API開発者ガイドを参考にさせて頂きました。
環境
cURLコマンドでSalesforce REST APIを呼び出す環境については、以下で作成したAWS EC2インスタンス(Amazon Linux)を使用しました。
cURLコマンドでSalesforce REST APIへ接続する為の準備
cURLコマンドを実行するインスタンスに、Salesforce REST APIへ接続する為に必要なOpenSSL 1.0.1以上がインストールされている事を確認します。
[ec2-user@salesforce-api-test ~]$ rpm -qa | grep openssl
openssl-1.0.1k-15.93.amzn1.x86_64
[ec2-user@salesforce-api-test ~]$
Salesforce REST APIのレスポンスはjsonで返ってくるので、jqコマンドをインストールしておくと、jsonパースが捗ります。
[ec2-user@salesforce-api-test ~]$ sudo yum install jq
cURLコマンドを実行するユーザの.bashrcに、Salesforce REST APIを呼び出す為の環境変数(SalesforceのOAuthコンシューマキーやシークレット等)を追加します。
[ec2-user@salesforce-api-test ~]$ vi /home/ec2-user/.bashrc
(末尾に以下を追加する)
### Sandbox環境へ接続する場合のAPIエンドポイント
##export DATABASEDOTCOM_HOST="test.salesforce.com"
### 本番環境へ接続する場合のAPIエンドポイント
export DATABASEDOTCOM_HOST="login.salesforce.com"
export DATABASEDOTCOM_CLIENT_ID="前述の「コンシューマ鍵」(OAuthコンシューマキー)を記載します。"
export DATABASEDOTCOM_CLIENT_SECRET="前述の「コンシューマの秘密」(OAuthコンシューマシークレット)を記載します。"
export DATABASEDOTCOM_CLIENT_USERNAME="APIを有効化しているSalesforceユーザアカウント名を記載します。"
export DATABASEDOTCOM_CLIENT_AUTHENTICATE_PASSWORD="APIを有効化しているSalesforceユーザアカウントのパスワードを記載します。"
.bashrcに設定した環境変数を読み込みます。
[ec2-user@salesforce-api-test ~]$ source /home/ec2-user/.bashrc
[ec2-user@salesforce-api-test ~]$
Salesforceへ接続し、OAuthアクセストークンを環境変数にセットします。
[ec2-user@salesforce-api-test ~]$ export DATABASEDOTCOM_ACCESS_TOKEN=`curl -s https://$DATABASEDOTCOM_HOST/services/oauth2/token -d "grant_type=password" -d "client_id=$DATABASEDOTCOM_CLIENT_ID" -d "client_secret=$DATABASEDOTCOM_CLIENT_SECRET" -d "username=$DATABASEDOTCOM_CLIENT_USERNAME" -d "password=$DATABASEDOTCOM_CLIENT_AUTHENTICATE_PASSWORD" | awk 'BEGIN{FS="access_token\":"}{print $2}' | awk 'BEGIN{FS=","}{print $1}' | sed -s 's/\"//g'`
[ec2-user@salesforce-api-test ~]$
Salesforceへの接続と認証に問題なければ、OAuthアクセストークンを取得出来ます。このOAuthアクセストークンを使って、cURLコマンドでSalesforce REST APIを呼び出します。
[ec2-user@salesforce-api-test ~]$ echo $DATABASEDOTCOM_ACCESS_TOKEN
00D28*****************************************************************************************************qVc2V5
[ec2-user@salesforce-api-test ~]$
SalesforceインスタンスのURLも取得して環境変数にセットします。
[ec2-user@salesforce-api-test ~]$ export DATABASEDOTCOM_INSTANCE_URL=`curl -s https://$DATABASEDOTCOM_HOST/services/oauth2/token -d "grant_type=p
assword" -d "client_id=$DATABASEDOTCOM_CLIENT_ID" -d "client_secret=$DATABASEDOTCOM_CLIENT_SECRET" -d "username=$DATABASEDOTCOM_CLIENT_USERNAME"
-d "password=$DATABASEDOTCOM_CLIENT_AUTHENTICATE_PASSWORD" | awk 'BEGIN{FS="instance_url\":"}{print $2}' | awk 'BEGIN{FS=","}{print $1}' | sed -s
's/\"//g'`
[ec2-user@salesforce-api-test ~]$
[ec2-user@salesforce-api-test ~]$ echo $DATABASEDOTCOM_INSTANCE_URL
https://ap2.salesforce.com
[ec2-user@salesforce-api-test ~]$
cURLコマンドでSalesforceの使用可能なリソースのリストを取得する例
Salesforce(この例ではバージョン 24.0)で使用可能なリソースのリストを取得します。
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/ -H "Authorization: Bearer $DATABASEDOTCOM_ACCESS_TOKE
N" -H "X-PrettyPrint:1" | jq '.'
{
"tooling": "/services/data/v24.0/tooling",
"async-queries": "/services/data/v24.0/async-queries",
"query": "/services/data/v24.0/query",
"chatter": "/services/data/v24.0/chatter",
"wave": "/services/data/v24.0/wave",
"exchange-connect": "/services/data/v24.0/exchange-connect",
"search": "/services/data/v24.0/search",
"identity": "https://login.salesforce.com/id/0***************/0************",
"sobjects": "/services/data/v24.0/sobjects",
"serviceTemplates": "/services/data/v24.0/serviceTemplates",
"recent": "/services/data/v24.0/recent",
"connect": "/services/data/v24.0/connect",
"licensing": "/services/data/v24.0/licensing"
}
[ec2-user@salesforce-api-test ~]$
cURLコマンドでSalesforceの使用可能なオブジェクトのリストを取得する例
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/sobjects/ -H "Authorization: Bearer $DATABASEDOTCOM_ACCESS_TOKEN" -H "X-PrettyPrint:1" | jq '.'
{
"encoding": "UTF-8",
"maxBatchSize": 200,
"sobjects": [
{
"activateable": false,
"createable": true,
"custom": false,
"customSetting": false,
"deletable": true,
"deprecatedAndHidden": false,
"feedEnabled": true,
"keyPrefix": "001",
"label": "取引先",
"labelPlural": "取引先",
"layoutable": true,
"mergeable": true,
"name": "Account",
"queryable": true,
"replicateable": true,
"retrieveable": true,
"searchable": true,
"triggerable": true,
"undeletable": true,
"updateable": true,
"urls": {
"rowTemplate": "/services/data/v24.0/sobjects/Account/{ID}",
"describe": "/services/data/v24.0/sobjects/Account/describe",
"sobject": "/services/data/v24.0/sobjects/Account"
}
},
(出力結果が長いので中略)
{
"activateable": false,
"createable": true,
"custom": true,
"customSetting": false,
"deletable": true,
"deprecatedAndHidden": false,
"feedEnabled": true,
"keyPrefix": "a03",
"label": "テストオブジェクト",
"labelPlural": "テストオブジェクト",
"layoutable": true,
"mergeable": false,
"name": "QuickStart__c",
"queryable": true,
"replicateable": true,
"retrieveable": true,
"searchable": true,
"triggerable": true,
"undeletable": true,
"updateable": true,
"urls": {
"rowTemplate": "/services/data/v24.0/sobjects/QuickStart__c/{ID}",
"describe": "/services/data/v24.0/sobjects/QuickStart__c/describe",
"sobject": "/services/data/v24.0/sobjects/QuickStart__c"
}
},
(出力結果が長いので中略)
{
"activateable": false,
"createable": true,
"custom": false,
"customSetting": false,
"deletable": true,
"deprecatedAndHidden": false,
"feedEnabled": false,
"keyPrefix": "083",
"label": "投票",
"labelPlural": "投票",
"layoutable": false,
"mergeable": false,
"name": "Vote",
"queryable": true,
"replicateable": true,
"retrieveable": true,
"searchable": false,
"triggerable": false,
"undeletable": false,
"updateable": false,
"urls": {
"rowTemplate": "/services/data/v24.0/sobjects/Vote/{ID}",
"describe": "/services/data/v24.0/sobjects/Vote/describe",
"sobject": "/services/data/v24.0/sobjects/Vote"
}
}
]
}
[ec2-user@salesforce-api-test ~]$
cURLコマンドでSalesforceオブジェクトの基本情報を取得する例
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/sobjects/QuickStart__c/ -H "Authorization: Bearer $DAT
ABASEDOTCOM_ACCESS_TOKEN" -H "X-PrettyPrint:1" | jq '.'
{
"objectDescribe": {
"activateable": false,
"createable": true,
"custom": true,
"customSetting": false,
"deletable": true,
"deprecatedAndHidden": false,
"feedEnabled": true,
"keyPrefix": "a03",
"label": "テストオブジェクト",
"labelPlural": "テストオブジェクト",
"layoutable": true,
"mergeable": false,
"name": "QuickStart__c",
"queryable": true,
"replicateable": true,
"retrieveable": true,
"searchable": true,
"triggerable": true,
"undeletable": true,
"updateable": true,
"urls": {
"rowTemplate": "/services/data/v24.0/sobjects/QuickStart__c/{ID}",
"describe": "/services/data/v24.0/sobjects/QuickStart__c/describe",
"sobject": "/services/data/v24.0/sobjects/QuickStart__c"
}
},
"recentItems": [
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8dDmAAJ"
},
"Id": "a032800000G8dDmAAJ",
"Name": "16"
},
(出力結果が長いので中略)
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcBAAR"
},
"Id": "a032800000G7wcBAAR",
"Name": "3"
}
]
}
[ec2-user@salesforce-api-test ~]$
cURLコマンドでSalesforceオブジェクトの各項目名やデータ型リストを取得する例
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/sobjects/QuickStart__c/describe/ -H "Authorization: Bearer $DATABASEDOTCOM_ACCESS_TOKEN" -H "X-PrettyPrint:1" | jq '.'
{
"activateable": false,
"childRelationships": [
{
"cascadeDelete": true,
"childSObject": "ActivityHistory",
"deprecatedAndHidden": false,
"field": "WhatId",
"relationshipName": "ActivityHistories"
},
{
"cascadeDelete": true,
"childSObject": "Attachment",
"deprecatedAndHidden": false,
"field": "ParentId",
"relationshipName": "Attachments"
},
{
"cascadeDelete": true,
"childSObject": "ContentDocumentLink",
"deprecatedAndHidden": false,
"field": "LinkedEntityId",
"relationshipName": null
},
{
"cascadeDelete": false,
"childSObject": "ContentVersion",
"deprecatedAndHidden": false,
"field": "FirstPublishLocationId",
"relationshipName": null
},
{
"cascadeDelete": true,
"childSObject": "EntitySubscription",
"deprecatedAndHidden": false,
"field": "ParentId",
"relationshipName": "FeedSubscriptionsForEntity"
},
(出力結果が長いので中略)
{
"autoNumber": false,
"byteLength": 90,
"calculated": false,
"calculatedFormula": null,
"caseSensitive": false,
"controllerName": null,
"createable": true,
"custom": true,
"defaultValue": null,
"defaultValueFormula": null,
"defaultedOnCreate": false,
"dependentPicklist": false,
"deprecatedAndHidden": false,
"digits": 0,
"externalId": false,
"filterable": true,
"groupable": true,
"htmlFormatted": false,
"idLookup": false,
"inlineHelpText": "ユーザ名を格納する項目。",
"label": "user_name",
"length": 30,
"name": "user_name__c",
"nameField": false,
"namePointing": false,
"nillable": false,
"permissionable": false,
"picklistValues": [],
"precision": 0,
"referenceTo": [],
"relationshipName": null,
"relationshipOrder": null,
"restrictedPicklist": false,
"scale": 0,
"soapType": "xsd:string",
"sortable": true,
"type": "string",
"unique": true,
"updateable": true,
"writeRequiresMasterRead": false
},
{
"autoNumber": false,
"byteLength": 765,
"calculated": false,
"calculatedFormula": null,
"caseSensitive": false,
"controllerName": null,
"createable": true,
"custom": true,
"defaultValue": null,
"defaultValueFormula": null,
"defaultedOnCreate": false,
"dependentPicklist": false,
"deprecatedAndHidden": false,
"digits": 0,
"externalId": false,
"filterable": true,
"groupable": true,
"htmlFormatted": false,
"idLookup": false,
"inlineHelpText": "ユーザのEメールアドレスを格納する項目です。",
"label": "user_email",
"length": 255,
"name": "user_email__c",
"nameField": false,
"namePointing": false,
"nillable": false,
"permissionable": false,
"picklistValues": [],
"precision": 0,
"referenceTo": [],
"referenceTo": [],
"relationshipName": null,
"relationshipOrder": null,
"restrictedPicklist": false,
"scale": 0,
"soapType": "xsd:string",
"sortable": true,
"type": "string",
"unique": true,
"updateable": true,
"writeRequiresMasterRead": false
},
{
"autoNumber": false,
"byteLength": 0,
"calculated": false,
"calculatedFormula": null,
"caseSensitive": false,
"controllerName": null,
"createable": true,
"custom": true,
"defaultValue": null,
"defaultValueFormula": null,
"defaultedOnCreate": false,
"dependentPicklist": false,
"deprecatedAndHidden": false,
"digits": 0,
"externalId": false,
"filterable": true,
"groupable": true,
"htmlFormatted": false,
"idLookup": false,
"inlineHelpText": null,
"label": "create_date",
"length": 0,
"name": "create_date__c",
"nameField": false,
"namePointing": false,
"nillable": true,
"permissionable": true,
"picklistValues": [],
"precision": 0,
"referenceTo": [],
"relationshipName": null,
"relationshipOrder": null,
"restrictedPicklist": false,
"scale": 0,
"soapType": "xsd:date",
"sortable": true,
"type": "date",
"unique": false,
"updateable": true,
"writeRequiresMasterRead": false
}
],
"keyPrefix": "a03",
"label": "テストオブジェクト",
"labelPlural": "テストオブジェクト",
"layoutable": true,
"listviewable": null,
"lookupLayoutable": null,
"mergeable": false,
"name": "QuickStart__c",
"queryable": true,
"recordTypeInfos": [
{
"available": true,
"defaultRecordTypeMapping": true,
"name": "マスタ",
"recordTypeId": "012000000000000AAA"
}
],
"replicateable": true,
"retrieveable": true,
"searchLayoutable": null,
"searchable": true,
"triggerable": true,
"undeletable": true,
"updateable": true,
"urls": {
"rowTemplate": "/services/data/v24.0/sobjects/QuickStart__c/{ID}",
"uiDetailTemplate": "https://ap2.salesforce.com/{ID}",
"uiEditTemplate": "https://ap2.salesforce.com/{ID}/e",
"describe": "/services/data/v24.0/sobjects/QuickStart__c/describe",
"uiNewRecord": "https://ap2.salesforce.com/a03/e",
"sobject": "/services/data/v24.0/sobjects/QuickStart__c"
}
}
[ec2-user@salesforce-api-test ~]$
cURLコマンドでSOQLによりSalesforceオブジェクトに登録しているレコードを表示する例
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/query?q=SELECT+user_name__c%2cuser_email__c%2ccreate_date__c+FROM+QuickStart__c -H "Authorization: Bearer $DATABASEDOTCOM_ACCESS_TOKEN" -H "X-PrettyPrint:1" | jq '.'
{
"totalSize": 16,
"done": true,
"records": [
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000FlloBAAR"
},
"user_name__c": "テスト太郎",
"user_email__c": "test.tarou@example.com",
"create_date__c": null
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000FlloVAAR"
},
"user_name__c": "テスト次郎",
"user_email__c": "test.jirou@example.com",
"create_date__c": null
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8d8SAAR"
},
"user_name__c": "testname_20160907_013814",
"user_email__c": "testname_20160907_013814@hoge.example.com",
"create_date__c": "2016-09-07"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8d7yAAB"
},
"user_name__c": "testname_20160907_013750",
"user_email__c": "testname_20160907_013750@hoge.example.com",
"create_date__c": "2016-09-07"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8d9pAAB"
},
"user_name__c": "testname_20160907_013850",
"user_email__c": "testname_20160907_013850@hoge.example.com",
"create_date__c": "2016-09-07"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8d0EAAR"
},
"user_name__c": "testname_20160907_013037",
"user_email__c": "testname_20160907_013037@hoge.example.com",
"create_date__c": "2016-09-07"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8dAiAAJ"
},
"user_name__c": "testname_20160907_013909",
"user_email__c": "testname_20160907_013909@hoge.example.com",
"create_date__c": "2016-09-07"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8dDmAAJ"
},
"user_name__c": "testname_20160907_015543",
"user_email__c": "testname_20160907_015543@hoge.example.com",
"create_date__c": "2016-09-07"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8dC0AAJ"
},
"user_name__c": "testname_20160907_014059",
"user_email__c": "testname_20160907_014059@hoge.example.com",
"create_date__c": "2016-09-07"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G8dCFAAZ"
},
"user_name__c": "testname_20160907_014210",
"user_email__c": "testname_20160907_014210@hoge.example.com",
"create_date__c": "2016-09-07"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcGAAR"
},
"user_name__c": "testname_20160906_042408",
"user_email__c": "testname_20160906_042408@hoge.example.com",
"create_date__c": "2016-09-06"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcQAAR"
},
"user_name__c": "testname_20160906_042527",
"user_email__c": "testname_20160906_042527@hoge.example.com",
"create_date__c": "2016-09-06"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcuAAB"
},
"user_name__c": "testname_20160906_043918",
"user_email__c": "testname_20160906_043918@hoge.example.com",
"create_date__c": "2016-09-06"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcBAAR"
},
"user_name__c": "testname_20160906_042126",
"user_email__c": "testname_20160906_042126@hoge.example.com",
"create_date__c": "2016-09-06"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wdEAAR"
},
"user_name__c": "testname_20160906_044112",
"user_email__c": "testname_20160906_044112@hoge.example.com",
"create_date__c": "2016-09-06"
},
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcLAAR"
},
"user_name__c": "testname_20160906_042515",
"user_email__c": "testname_20160906_042515@hoge.example.com",
"create_date__c": "2016-09-06"
}
]
}
[ec2-user@salesforce-api-test ~]$
cURLコマンドでSalesforceオブジェクトの指定したレコードを表示する例
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcLAAR -H "Authoriz
ation: Bearer $DATABASEDOTCOM_ACCESS_TOKEN" -H "X-PrettyPrint:1" | jq '.'
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcLAAR"
},
"Id": "a032800000G7wcLAAR",
"OwnerId": "00528000004XbW2AAK",
"IsDeleted": false,
"Name": "5",
"CreatedDate": "2016-09-05T19:25:15.000+0000",
"CreatedById": "00528000004XbW2AAK",
"LastModifiedDate": "2016-09-05T19:25:15.000+0000",
"LastModifiedById": "00528000004XbW2AAK",
"SystemModstamp": "2016-09-05T19:25:15.000+0000",
"LastActivityDate": null,
"user_name__c": "testname_20160906_042515",
"user_email__c": "testname_20160906_042515@hoge.example.com",
"create_date__c": "2016-09-06"
}
[ec2-user@salesforce-api-test ~]$
cURLコマンドでSalesforceオブジェクトのレコードの項目を更新する例
Salesforce REST APIでレコードを更新するので、更新データを記載したjsonファイルを作成します。
[ec2-user@salesforce-api-test ~]$ vi example.json
{
"user_name__c" : "SalesForce APIテスト",
"user_email__c" : "example@hoge.example.com",
"create_date__c" : "2016-09-07"
}
[ec2-user@salesforce-api-test ~]$ cat example.json | jq '.'
{
"user_name__c": "SalesForce APIテスト",
"user_email__c": "example@hoge.example.com",
"create_date__c": "2016-09-07"
}
[ec2-user@salesforce-api-test ~]$
まず変更前のForce.comオブジェクトのレコードを確認します。
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcLAAR -H "Authorization: Bearer $DATABASEDOTCOM_ACCESS_TOKEN" -H "X-PrettyPrint:1" | jq '.'
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcLAAR"
},
"Id": "a032800000G7wcLAAR",
"OwnerId": "00528000004XbW2AAK",
"IsDeleted": false,
"Name": "5",
"CreatedDate": "2016-09-05T19:25:15.000+0000",
"CreatedById": "00528000004XbW2AAK",
"LastModifiedDate": "2016-09-05T19:25:15.000+0000",
"LastModifiedById": "00528000004XbW2AAK",
"SystemModstamp": "2016-09-05T19:25:15.000+0000",
"LastActivityDate": null,
"user_name__c": "testname_20160906_042515",
"user_email__c": "testname_20160906_042515@hoge.example.com",
"create_date__c": "2016-09-06"
}
[ec2-user@salesforce-api-test ~]$
cURLコマンドでSalesforce REST APIを呼び出し、指定したForce.comオブジェクトのレコードを更新します。
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcLAAR -H "Authorization: Bearer $DATABASEDOTCOM_ACCESS_TOKEN" -H "X-PrettyPrint:1" -H "Content-Type:application/json" --data-binary @example.json -X PATCH | jq '.'
[ec2-user@salesforce-api-test ~]$
先ほど指定したForce.comのオブジェクトのレコードが更新されている事を確認します。
[ec2-user@salesforce-api-test ~]$ curl -s $DATABASEDOTCOM_INSTANCE_URL/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcLAAR -H "Authorization: Bearer $DATABASEDOTCOM_ACCESS_TOKEN" -H "X-PrettyPrint:1" | jq '.'
{
"attributes": {
"type": "QuickStart__c",
"url": "/services/data/v24.0/sobjects/QuickStart__c/a032800000G7wcLAAR"
},
"Id": "a032800000G7wcLAAR",
"OwnerId": "00528000004XbW2AAK",
"IsDeleted": false,
"Name": "5",
"CreatedDate": "2016-09-05T19:25:15.000+0000",
"CreatedById": "00528000004XbW2AAK",
"LastModifiedDate": "2016-09-07T17:58:19.000+0000",
"LastModifiedById": "00528000004XbW2AAK",
"SystemModstamp": "2016-09-07T17:58:19.000+0000",
"LastActivityDate": null,
"user_name__c": "SalesForce APIテスト",
"user_email__c": "example@hoge.example.com",
"create_date__c": "2016-09-07"
}
[ec2-user@salesforce-api-test ~]$
cURLコマンドでChatterへメッセージを投稿する例
cURLコマンドによりChatterへメッセージを投稿する方法については、こちらの記事 をご参照下さい。
以上になります。