0% found this document useful (0 votes)
202 views

SF Rest API Cheatsheet Web

The document provides an overview of the Force.com REST API: - The REST API allows interacting with Force.com using HTTP requests to resources identified by URIs. It supports CRUD operations on objects using HTTP methods and authentication via OAuth. - Common resources include sObjects for CRUD, composite for batch requests, query for SOQL, and describe for metadata. - Requests should specify the HTTP method, session ID, format, and URI. Responses use HTTP codes and include error details in the body.

Uploaded by

werqr2wr23
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
202 views

SF Rest API Cheatsheet Web

The document provides an overview of the Force.com REST API: - The REST API allows interacting with Force.com using HTTP requests to resources identified by URIs. It supports CRUD operations on objects using HTTP methods and authentication via OAuth. - Common resources include sObjects for CRUD, composite for batch requests, query for SOQL, and describe for metadata. - Requests should specify the HTTP method, session ID, format, and URI. Responses use HTTP codes and include error details in the body.

Uploaded by

werqr2wr23
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Force.

com REST API


Cheatsheet

Overview
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).

Common Requests for Working with SObjects Other Common Resources


HTTP Request Resource
Action URL URL Description
Method Body Name
Versions / Lists summary information
https://instance. field- about each Salesforce version
Create a currently available, including
salesforce.com/services/ POST value
Record the version, label, and a link
data/vNN.N/sobjects/ pairs
to each version's root.
Resources /vNN.N/ Lists available resources for
by Version the specified API version,
https://instance.
including resource name
Delete a salesforce.com/services/
DELETE N/A and URI.
Record data/vNN.N/sobjects/
Limits /vNN.N/limits/ Lists information about limits
sObject/Id
in your organization.
SObject /vNN.N/sobjects/ Describes the individual
Basic SObject/ metadata for the specified
https://instance.
field- Information object.
Update a salesforce.com/services/
PATCH value SObject /vNN.N/sobjects/ Creates new records or
Record data/vNN.N/sobjects/
pairs Rows By SObjectName/ updates existing records
sObject/Id
External ID fieldName/ (upserts records) based
fieldValue on the value of a specified
external ID field.
https://instance.
field- SObject /vNN.N/ Retrieves the specified
Upsert a salesforce.com/services/ sobjects/
PATCH value Blob blob field from an
Record data/vNN.N/sobjects/sObject/ Retrieve SObject/Id/ individual record.
pairs
externalIdField/value blobField
Query /vNN.N/ Executes the specified SOQL
query/?q= query. The query string must
https://instance. soqlQuery be URL-encoded.
Describe
salesforce.com/services/ GET N/A QueryAll /vNN.N/ Executes the specified SOQL
Global
data/vNN.N/sobjects/ queryAll/?= query. The query string must
soqlQuery be URL-encoded. Unlike the
Query resource, QueryAll will
https://instance.salesforce. return records that have been
Describe deleted because of a merge
com/services/data/vNN.N/ GET N/A
SObject or delete.
sobjects/sObject/describe
Search /vNN.N/search/ Executes the specified SOSL
?s=soslQuery search. The search string
must be URL-encoded.
• HTTP requests to a REST API resource should contain the
following information: Batch /vNN.N/ Executes up to 25
composite/ subrequests in a single
• An HTTP method (HEAD, GET, POST, PATCH, or DELETE). batch request to improve your
• A session ID or an OAuth 2.0 access token used to authenticate application’s performance.
the request. SObject /vNN.N/ Creates one or more sObject
Tree composite/tree/ trees with root records of the
• An HTTP ACCEPT header that indicates the resource format
(JSON or XML), or a .json or .xml extension to the URI. SObject specified type. An sObject
The default is JSON. tree is a collection of nested,
parent-child records with a
• The Force.com or Database.com REST resource. single root record. Can also
be used to create up to 200
• Any JSON or XML data containing information needed for the unrelated records of the
request, such as the data required when updating a record.
same type.
Force.com REST API Cheatsheet

REST API Header HTTP Error Codes


REST API supports the following headers:
When errors occur, the response header contains an HTTP code, and
Header Description Example the response body typically contains the error code, the message
accompanying that error, and the field or object where the error
Content-Type Specifies whether Content-Type:
occurred.
the request is application/json
formatted as
JSON or XML. The value used for an external ID exists in more
300 than one record. The response body contains
Authorization Authorization: the list of matching records.
Used to
authenticate OAuth sessionId
the request. The request could not be understood, usually
400
because the JSON or XML body has an error.
X-Pretty-Print Formats the X-PrettyPrint:1
response in a more The session ID or OAuth token used has expired
readable format 401 or is invalid. The response body contains the
with line breaks message and errorCode.
and indentation.
The request has been refused. Verify that the
Accept Indicates the Accept: 403
logged-in user has appropriate permissions.
resource format application/xml
which can be either
JSON or XML. The requested resource could not be found.
404 Check the URI for errors, and verify that there
X-Sfdc- Specifies the x-sfdc- are no sharing issues.
PackageVersion package version packageversion-
under which context namespace: 2.0
an API call is made.
HTTP Succcess Codes
Sforce-Auto- Specifies whether Sforce-Auto-Assign:
Assign active assignment TRUE When a request is successful, the response header contains an HTTP
rules should be used code, and the response body contains a Boolean success value.
when creating or
updating Cases or
Leads. 200 The request has been successfully processed.

Sforce-Call- Specifies client- Sforce-Call-


Options Options: 201 The request has been successfully processed and
specific options
client=SampleCase the resource has been created.
when accessing
the following REST SensitiveToken/100,
resources: SObjet defaultNamespace= 204 The request has been successfully processed, but
Basic Information, battle no content is returned in the response body. This
SObject Rows, code is returned after a resource is successfully
Query, QueryAll, deleted.
Search, and SObject
Rows by External ID

Sforce-Limit- Returns limit Sforce-Limit-Info:


Info information for the api-usage=14/5000 HTTP Methods
organization.
REST API supports the following HTTP methods:
Sforce-Query- Specifies options Sforce-Query-
Options used in the query, Options:
such as the query batchSize=1000 GET Retrieves information, such as basic resource
results batch size. summary information.

HEAD Retrieves resource metadata.

Examples
PATCH Updates a record.
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 POST Creates a new object.
escaped with a backslash (\!) when used in cURL commands.
Depending on your platform, request headers may require single
DELETE Deletes a record.
quotes (‘) or double quotes (“).
Create an Invoice Statement Execute a Query
cURL Command cURL Command
curl https://instance.salesforce.com/ curl https://instance.salesforce.com/services/
services/data/v24.0/sobjects/Invoice _ data/v24.0/query?q=SELECT+Id,+Name,+Status _ _
Statement _ _ c/ -H "Content-Type:application/ c+FROM+Invoice _ Statement __ c -H “Authorization:
json" -d "{\"Description _ _ c\" : \"New invoice OAuth token” -H “X-PrettyPrint:1”
statement\"}" -H “Authorization: OAuth token" -H
“X-PrettyPrint:1"
Response (JSON)
Response (JSON) {
{ “done” : true,
"id" : "a00D0000008oLd7IAE", “totalSize” : 3,
"errors" : [ ], “records” : [ {
"success" : true “attributes” : {
} “type” : “Invoice_Statement__c”,
“url” : “/services/data/v24.0/sobjects/
Invoice_Statement__c/a00D0000008o6y
3IAA”
},
Update status__c on Invoice_Statement__c “Id” : “a00D0000008o6y3IAA”,
cURL Command “Name” : “INV-0000”,
curl https://instance.salesforce.com/services/ “Status__c” : “Open”
data/v24.0/sobjects/Invoice _ Statement _ _ c/ }, {
a00D0000008o6yDIAQ -H "Authorization: OAuth “attributes” : {
token" -H "Content-Type: application/json" “type” : “Invoice_Statement__c”,
-d "{\"Status _ _ c\" : \"Open\"}" -X PATCH -H “url” : “/services/data/v24.0/sobjects/
"X-PrettyPrint:1" Invoice_Statement__c/a00D0000008o6y
DIAQ”
Response (JSON) },
N/A “Id” : “a00D0000008o6yDIAQ”,
“Name” : “INV-0002”,
“Status__c” : “Closed”
} ]
}
Delete an Invoice Statement
cURL Command
curl https://instance.salesforce.com/services/
data/v24.0/sobjects/Invoice _ Statement _ _ c/ OAuth Username/Password Authentication
a00D0000008oLd7IAE -H "Authorization: OAuth
token" -H "X-PrettyPrint:1" -X DELETE cURL Command
curl https://login.salesforce.com/
Response (JSON) services/oauth2/token -d 'grant _
N/A type=password&client _ id=REMOTE _ ACCESS _
CLIENT _ ID&client _ secret=REMOTE _ ACCESS _
CLIENT _ SECRET&username=user@example.
com&password=********' -H "X-PrettyPrint: 1"
Search for a String
cURL Command Response (JSON)
curl https://instance.salesforce.com/services/ {
data/v24.0/search/?q=FIND+%7Bcountry%7D -H "id" : "https://login.salesforce.com/
"Authorization: OAuth token" -H "X-PrettyPrint:1" id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
Response (JSON) "issued _ at" : "1322006414073",
[ { "instance _ url" :
"attributes" : { "https://instance.salesforce.com",
"type" : "Invoice _ Statement _ _ c", "signature" : "3/
"url" : "/services/data/v24.0/sobjects/ FtJxcTxvpwJx8Tloc/4oNVz1hhzIuppTCOQdrJSjA=",
Invoice _ Statement _ _ c/a00D0000008o6yDIAQ" "access _ token" : "00D50000000IZ3Z!AQ0AQNag4tr.
}, S15f0LoborG12HIls6eEzIxLafInLZIf6RbFiwV2Pjq6 _
"Id" : "a00D0000008o6yDIAQ" QHB4J64a6vSMS705Y _ sIVE _ lq _ xnLIXBXgOKPEo"
} ] }
Force.com REST API Cheatsheet

Create Multiple Records Update a Record and Get Its Field Values in a
Single Request
cURL Command:
curl https://na1.salesforce.com/services/data/
v34.0/composite/tree/Account/ -H "Authorization: cURL Command:
Bearer token -H "Content-Type: application/json" curl https://na1.salesforce.com/services/data/
-d "@newrecords.json" v34.0/composite/batch/ -H "Authorization: Bearer
token -H "Content-Type: application/json" -d
Example request body newrecords.json for creating four "@batch.json"
new accounts:
{ Request body batch.json file:
"records" :[{ {
"attributes" : {"type" : "Account", "batchRequests" : [
"referenceId" : "ref1"}, {
"name" : "SampleAccount1", "method" : "PATCH",
"phone" : "1111111111", "url" : "v34.0/sobjects/account/
"website" : "www.salesforce1.com", 001D000000K0fXOIAZ",
"numberOfEmployees" : "100", "richInput" : {"Name" : “NewName"}
"type" : "Analyst", },{
"industry" : "Banking" "method" : "GET",
},{ "url" : "v34.0/sobjects/
"attributes" : {"type" : "Account", account/001D000000K0fXOIAZ?fields=Name,
"referenceId" : "ref2"}, BillingPostalCode"
"name" : "SampleAccount2",
"phone" : "2222222222", }]
"website" : "www.salesforce2.com", }
"numberOfEmployees" : "250", Response body after successfully executing the subrequests:
"type" : "Analyst", {
"industry" : "Banking" "hasErrors" : false,
},{ "results" : [{
"attributes" : {“type" : “Account", "statusCode" : 204,
"referenceId" : "ref3"}, "result" : null
"name" : “SampleAccount3", },{
"phone" : “3333333333", "statusCode" : 200,
"website" : “www.salesforce3.com",
"numberOfEmployees" : “52000", "result": {
"type" : “Analyst", "attributes" : {
"industry" : “Banking" "type" : "Account",
},{ "url" : "/services/data/v34.0/
"attributes" : {"type" : “Account", sobjects/Account/001D000000K0fXOIAZ"
"referenceId" : "ref4"}, },
"name" : “SampleAccount4", "Name" : “NewName",
"phone" : “4444444444", "BillingPostalCode" : "94105",
"website" : “www.salesforce4.com", "Id" : "001D000000K0fXOIAZ"
"numberOfEmployees" : “2500", }
"type" : “Analyst", }]
"industry" : “Banking" }
}]
}
Example request body newrecords.json for creating four
new accounts:
{
"hasErrors" : false,
"results" : [{
"referenceId" : "ref1",
"id" : “001D000000K1YFjIAN"
},{
"referenceId" : "ref2",
"id" : “001D000000K1YFkIAN"
},{
"referenceId" : "ref3",
"id" : “003D000000K1YFlIAN"
},{
"referenceId" : "ref4",
"id" : “003D000000K1YFmIAN"
}]
}

For other cheatsheets:


http://developer.salesforce.com/cheatsheets 10042016

You might also like