Inteagration REST API Cheat Sheet
Inteagration REST API Cheat Sheet
Overview
The Force.com REST API provides you with a powerful Web services API that you can use to interact with Force.com.
Each resource in REST API is a named URI that's used with an HTTP method: HEAD, GET, POST, PATCH, or DELETE. All resources are accessed using a generic interface over
HTTP with a base URI that follows your Force.com or Database.com URI. REST API supports authentication using OAuth 2.0 and supports both JSON and XML ( JSON is the default).
REST Requests
Action
URL
HTTP Method
Request Body
Create
https://instance.salesforce.com/services/data/vNN.N/sobjects/
POST
field-value pairs
Delete
https://instance.salesforce.com/services/data/vNN.N/sobjects/Obj/Id
DELETE
N/A
Update
https://instance.salesforce.com/services/data/vNN.N/sobjects/Obj/Id
PATCH
field-value pairs
Upsert
https://instance.salesforce.com/services/data/vNN.N/sobjects/Obj/externalIdField/value
PATCH
field-value pairs
SOQL Query
https://instance.salesforce.com/services/data/vNN.N/query/?q=soqlQuery
GET
N/A
SOSL Search
https://instance.salesforce.com/services/data/vNN.N/search/?q=soslQuery
GET
N/A
Describe
https://instance.salesforce.com/services/data/vNN.N/sobjects/
GET
N/A
Describe SObject
https://instance.salesforce.com/services/data/vNN.N/sobjects/Obj
GET
N/A
HTTP requests to a REST API resource should contain the following information:
An HTTP method (HEAD, GET, POST, PATCH, or DELETE).
A session ID or an OAuth 2.0 access token used to authenticate the request.
An HTTP ACCEPT header that indicates the resource format ( JSON or XML), or a .json or .xml extension to the URI. The default is JSON.
The Force.com or Database.com REST resource.
Any JSON or XML data containing information needed for the request, such as the data required when updating a record.
Resources
Resource Name
URI
Description
Versions
Lists summary information about each Salesforce version currently available, including
the version, label, and a link to each version's root.
Resources by Version
/vNN.N/
Lists available resources for the specified API version, including resource name and URI.
Describe Global
/vNN.N/sobjects/
Lists available objects and their metadata for your organization's data.
/vNN.N/sobjects/SObject/
SObject Describe
/vNN.N/sobjects/SObject/describe
Completely describes the individual metadata at all levels for the specified object.
SObject Rows
/vNN.N/sobjects/SObject/id/
Accesses records based on the specified object ID. Retrieves, creates, updates, or
deletes records.
/vNN.N/sobjects/SObjectName/fieldName/
fieldValue
Creates new records or updates existing records (upserts records) based on the
value of a specified external ID field.
/vNN.N/sobjects/SObject/id/blobField
Query
/vNN.N/query/?q=soqlQuery
Executes the specified SOQL query. The query string must be URL-encoded.
Search
/vNN.N/search/?s=soslQuery
Executes the specified SOSL search. The search string must be URL-encoded.
http://developer.salesforce.com
Description
Example
Content-Type
Content-Type: application/json
Authorization
X-Pretty-Print
Formats the response in a more readable format with line breaks and
indentation.
X-PrettyPrint:1
Accept
Accept: application/xml
X-Sfdc-PackageVersionPackageName
Specifies the package version under which context an API call is made.
X-Sfdc-PackageVersion-MyPackage: 2.0
When errors occur, the response header contains an HTTP code, and the response body
typically contains the error code, the message accompanying that error, and the field or
object where the error occurred.
When a request is successful, the response header contains an HTTP code, and the response
body contains a Boolean success value.
300
400
403
The request has been refused. Verify that the logged-in user has
appropriate permissions.
404
The requested resource could not be found. Check the URI for
errors, and verify that there are no sharing issues.
405
500
201
The request has been successfully processed and the resource has
been created.
204
401
415
200
The value used for an external ID exists in more than one record.
The response body contains the list of matching records.
HTTP Methods
REST API supports the following HTTP methods:
GET
HEAD
PATCH
Updates a record.
POST
DELETE
Deletes a record.
Examples
Following are some examples of calling REST API using cURL. Replace token with your session ID. Depending on your platform, if the token contains an exclamation mark (!),
it should be escaped with a backslash (\!) when used in cURL commands. Depending on your platform, request headers may require single quotes (') or double quotes (").
Response (JSON)
{
"id" : "a00D0000008oLd7IAE",
"errors" : [ ],
"success" : true
}
Response (JSON)
N/A
Response (JSON)
N/A
Response (JSON)
[ {
"attributes" : {
"type" : "Invoice_Statement__c",
"url" : "/services/data/v24.0/sobjects/Invoice_Statement__c/a00D0000008o6yDIAQ"
},
"Id" : "a00D0000008o6yDIAQ"
} ]
Execute a Query
cURL Command
curl https://instance.salesforce.com/services/data/v24.0/query?q=SELECT+Id,+Name,+Status__c+FROM+Invoice_Statement__c -H
"Authorization: OAuth token" -H "X-PrettyPrint:1"
Response (JSON)
{
"done" : true,
"totalSize" : 3,
"records" : [ {
"attributes" : {
"type" : "Invoice_Statement__c",
"url" : "/services/data/v24.0/sobjects/Invoice_Statement__c/a00D0000008o6y
3IAA"
},
"Id" : "a00D0000008o6y3IAA",
"Name" : "INV-0000",
"Status__c" : "Open"
}, {
"attributes" : {
"type" : "Invoice_Statement__c",
"url" : "/services/data/v24.0/sobjects/Invoice_Statement__c/a00D0000008o6y
DIAQ"
},
"Id" : "a00D0000008o6yDIAQ",
"Name" : "INV-0002",
"Status__c" : "Closed"
} ]
}
Response (JSON)
{
"id" : "https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
"issued_at" : "1322006414073",
"instance_url" : "https://instance.salesforce.com",
"signature" : "3/FtJxcTxvpwJx8Tloc/4oNVz1hhzIuppTCOQdrJSjA=",
"access_token" : "00D50000000IZ3Z!AQ0AQNag4tr.S15f0LoborG12HIls6eEzIxLafInLZIf6RbFiwV2Pjq6_QHB4J64a6vSMS705Y_sIVE_lq_xnLIXBXgOKPEo"
}
10132014