REST API Developer Guide - Salesforce

Transcription

REST API Developer GuideVersion 55.0, Summer ’22@salesforcedocsLast updated: June 16, 2022

Copyright 2000–2022 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com, inc.,as are other names and marks. Other marks appearing herein may be trademarks of their respective owners.

CONTENTSChapter 1: REST API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1What Is REST API? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2API Compatible Editions and Development Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . 2REST Resources and Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3REST API Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Compression Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Conditional Request Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Send REST Requests with cURL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Authorization Through Connected Apps and OAuth 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Configure Salesforce CORS Allowlist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Valid Date and DateTime Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11API End-of-Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Chapter 2: Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Quick Start Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Step One: Set Up Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Step Two: Walk Through the Sample Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Using Other Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Chapter 3: Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Getting Information About My Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23List Available REST API Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23List Organization Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24List Available REST Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Get a List of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Get a List of Objects If Metadata Has Changed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Working with Object Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Retrieve Metadata for an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Get Field and Other Metadata for an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Get Object Metadata Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Working with Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Create a Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36Update a Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Delete a Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Get Field Values from a Standard Object Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Get Field Values from an External Object Record by Using the Salesforce ID . . . . . . . . . . 39Get Field Values from an External Object Record by Using the External ID StandardField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40Retrieve a Record Using an External ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

ContentsInsert or Update (Upsert) a Record Using an External ID . . . . . . . . . . . . . . . . . . . . . . . . 41Traverse Relationships with Friendly URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Get a List of Deleted Records Within a Given Timeframe . . . . . . . . . . . . . . . . . . . . . . . 50Get a List of Updated Records Within a Given Timeframe . . . . . . . . . . . . . . . . . . . . . . . 51Delete Lightning Experience Event Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Working with Searches and Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53Execute a SOQL Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53Execute a SOQL Query that Includes Deleted Items . . . . . . . . . . . . . . . . . . . . . . . . . . . 55Get Feedback on Query Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Search for a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Get the Default Search Scope and Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Get Search Result Layouts for Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61View Relevant Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Get an Image from a Rich Text Area Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Insert or Update Blob Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Retrieve Blob Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Working with Recently Viewed Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72View Recently Viewed Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Mark Records as Recently Viewed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Managing User Passwords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Manage User Passwords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Working with Approval Processes and Process Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76Get a List of All Approval Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Submit a Record for Approval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Approve a Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78Reject a Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78Bulk Approvals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Get a List of Process Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Get a Particular Process Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Trigger Process Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Using Event Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82Describe Event Monitoring Using REST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Query Event Monitoring Data with REST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84Get Event Monitoring Content from a Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85Download Large Event Log Files Using cURL with REST . . . . . . . . . . . . . . . . . . . . . . . . . 85Delete Event Monitoring Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86Query or View Hourly Event Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87Using Composite Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Execute Dependent Requests in a Single API Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Update an Account, Create a Contact, and Link Them with a Junction Object . . . . . . . . . 92Update a Record and Get Its Field Values in a Single Request . . . . . . . . . . . . . . . . . . . 93Upsert an Account and Create a Contact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94Create Nested Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95Create Multiple Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

ContentsUsing a Composite Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98Chapter 4: Generating an OpenAPI 3.0 Specification for sObjects REST API (Beta) . . . 103Chapter 5: Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114Resources by Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Describe Global . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119sObject Basic Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120Retrieve Object Metadata Using sObject Basic Information . . . . . . . . . . . . . . . . . . . . . 120Create Records Using sObject Basic Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121sObject Describe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121sObject Get Deleted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122sObject Get Updated . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123sObject Named Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125sObject Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Retrieve Records Using sObject Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126Update Records Using sObject Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127Delete Records Using sObject Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129sObject Rows by External ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130Retrieve Records Using sObject Rows by External ID . . . . . . . . . . . . . . . . . . . . . . . . . 130Create Records Using sObject Rows by External ID . . . . . . . . . . . . . . . . . . . . . . . . . . 131Upsert Records Using sObject Rows by External ID . . . . . . . . . . . . . . . . . . . . . . . . . . 132Delete Records Using sObject Rows by External ID . . . . . . . . . . . . . . . . . . . . . . . . . . 133Return Headers Using sObject Rows by External ID . . . . . . . . . . . . . . . . . . . . . . . . . . 134sObject Blob Retrieve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135sObject ApprovalLayouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135sObject CompactLayouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136sObject Describe Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142sObject PlatformAction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144sObject Quick Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145sObject Rich Text Image Retrieve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146sObject Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147sObject Suggested Articles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148sObject User Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150Platform Event Schema by Event Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Platform Event Schema by Schema ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155AppMenu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160Compact Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164Consent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166Use the Consent API with Salesforce CDP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173Consent Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177Embedded Service Configuration Describe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

ContentsInvocable Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181Standard Invocable Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183Custom Invocable Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186List View Describe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187List View Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190List Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Support Knowledge with REST API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Data Category Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Data Category Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206Articles List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208Articles Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212Parameterized Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224Process Approvals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226Process Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228Product Schedules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231Salesforce CDP Query Profile Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233QueryAll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234Quick Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235Recent List Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236Recently Viewed Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Record Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Record Count Response Body . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239sObject Relevant Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240Retrieve Knowledge Language Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242Search Scope and Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Search Result Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Lightning Toggle Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244Lightning Usage by App Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245Lightning Usage by Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246Lightning Usage by Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247Lightning Usage by FlexiPage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249Lightning Exit by Page Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Salesforce Scheduler Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251Get Appointment Slots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252Get Appointment Candidates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256Request Bodies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259Response Bodies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261Search for Records Suggested by Autocomplete and Instant Results . . . . . . . . . . . . . . . . . . 262Search Suggested Article Title Matches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268Search Suggested Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

ContentsSalesforce Surveys Translation Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272Add or Change the Translation of a Survey Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273Add or Update the Translated Value of Multiple Survey Fields in One or MoreLanguages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274Delete the Translated Value of a Survey Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276Delete the Translated Value of Multiple Survey Fields in One or More Languages . . . . . . 276Get Translated Value of a Survey Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277Get the Translated Values of Multiple Survey Fields in One or More Languages . . . . . . . 279Tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282Composite Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284Composite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285Composite Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304Composite Batch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318sObject Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322sObject Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340Assignment Rule Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341Call Options Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341Duplicate Rule Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342Limit Info Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343Package Version Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343Query Options Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344Warning Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344Status Codes and Error Responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345

CHAPTER 1In this chapter . What Is REST API? API CompatibleEditions andDevelopmentEnvironments REST Resources andRequests REST API Architecture CompressionHeaders Conditional RequestHeaders Send REST Requestswith cURL AuthorizationThrough ConnectedApps and OAuth 2.0 Configure SalesforceCORS Allowlist Valid Date andDateTime Formats API End-of-LifeREST APIREST API provides you with programmatic access to your data in Salesforce. The flexibility and scalabilityof REST API make it an excellent choice for integrating Salesforce into your applications and for performingcomplex operations on a large scale.Use this guide to set up your deployment environment and learn about advanced details regarding dataaccess. However, understanding and using REST API requires basic familiarity with software development,web services, and the Salesforce user interface.If you want to get right to the action, the Quick Start guide covers the basics to get you up and running.If you’re looking for more context about Salesforce APIs, check out the list of links.SEE ALSO:Trailhead: Lightning Platform API BasicsWhich API Do I Use?1

REST APIWhat Is REST API?What Is REST API?REST API is one of several web interfaces that you can use to access your Salesforce data without using the Salesforce user interface.With API access, you can perform operations and integrate Salesforce into your applications as you like.You can use REST API tools to create, manipulate, and search data in Salesforce by sending HTTP requests to endpoints in Salesforce.Depending on where you send requests, you access and operate on different pieces of information, called resources. Resources includerecords, query results, metadata, and more.REST API uses RESTful architecture to provide a straightforward and consistent interface. A primary benefit of REST API is that it doesn’trequire much tooling to access your data. It’s simpler to use than SOAP API but still provides plenty of functionality.Although REST API is great for accessing and querying records, other Salesforce APIs, such as Bulk 2.0 API, Metadata API, and ConnectREST API, offer additional functionality for specific tasks.SEE ALSO:REST Resources and RequestsREST API ArchitectureWhich API Do I Use?API Compatible Editions and Development EnvironmentsTo access your Salesforce data using APIs, you need a Salesforce org with API access and the API Enabled user permission within thatorg.API AccessAPI access is available with Professional Edition, Performance Edition, Enterprise Edition, Unlimited Edition, and Developer Edition. ForProfessional Edition, all requests for API access must be purchased and can be processed by contacting your Account Executive.Note: If you send an API request to an org without API access, Salesforce returns a API DISABLED FOR ORG error.To protect your live data, we recommend performing all development and testing in Developer Edition, sandboxes, or scratch orgs. Thisway you create a separate environment to try out things before implementing the changes.API Enabled PermissionWithin an org that has API access, your administrator must assign the API Enabled permission to your user profile. For Developer Edition,this permission is assigned by default. For more information, see User Permissions in Salesforce Help.SEE ALSO:Get your very own Developer EditionScratch OrgsSandboxesSalesforce DX Developer Guide2

REST APIREST Resources and RequestsREST Resources and RequestsREST API is based on the usage of resources—pieces of data in Salesforce, such as records, collections of records, query results, metadata,or API information. Each resource is exposed by a uniform resource identifier (URI) and is accessed by sending HTTP requests to thecorresponding URI.Depending on which resource you want to access and how you construct an HTTP request, you can perform several types of operations,including: Determine available API versions Access limits for your Salesforce org Retrieve object metadata Create, read, update, and delete records Query and search for dataYou can send HTTP requests using a variety of software tools, which means that the exact appearance of a request can look differentfrom the cURL examples in this guide. However, no matter how you submit requests, the elements don’t change. A typical requestconsists of these elements. URI HTTP method Headers Request body (not required for GET requests)URIsThe URI is the path to a resource in Salesforce. Although the URI changes from resource to resource, the basic structure remains vices/data/vXX.X/resource/Use https:// to securely access resources.Replace MyDomainName with the subdomain of your Salesforce org. Salesforce runs on multiple server instances, so the examplesin this guide use MyDomainName in place of a specific instance.Replace XX.X with the version of the API that you want to use. You can find a list of available versions by accessing the Versions onpage 114 resource.Replace resource with the rest of the path to the resource. Depending on the resource, the path can contain parameters, such asIDs to identify a specific record. You can find the URIs for different resources in the Reference section of this guide.Accessing sObject resources involves accessing standard and custom objects in Salesforce. You can find information about standardobjects in the Object Reference for Salesforce and Lightning Platform.Note: Some parts of URIs are case-sensitive, such as IDs. Other parts of URIs aren't case-sensitive, such as object and field names.If your requests aren't successful, check that your URI has the right letter cases by comparing the URI to the examples in this guide.HTTP MethodsREST API supports standard HTTP request methods (HEAD, GET, POST, PATCH, PUT, and DELETE), which follow the specifications 9.html.3

REST APIREST API ArchitectureThe purpose of each method varies depending on the resource. For information on how and when to use each method, check the pagefor that resource in the Reference section of this guide.HeadersUse headers to pass parameters and customize options for HTTP requests. REST API supports several standard HTTP headers, as well ascustom headers that are specific to Salesforce.Common headers used in the examples include: HTTP Accept—Indicates the format that your client accepts for the response body. Possible values are application/jsonand application/xml. The default value is application/json. HTTP Content-type—Indicates the format of the request body that you attach to the request. Possible values areapplication/json and application/xml. HTTP Authorization—Provides the OAuth 2.0 access token to authorize your client. REST API supports the Bearer authenticationtype. Compression header—Compresses the request or the response. For more information, see Compression Headers on page 6. Conditional request header—Validates the records that you access against a precondition. For more information, see ConditionalRequest Headers on page 6.Request BodiesA request body is a rich input that can be included in the request to provide additional information, such as field values for creating orupdating records. A request body can be in JSON or XML format.Note: Resources accessed with the GET method don’t require you

CHAPTER 1 REST API REST API provides you with programmatic access to your data in Salesforce. The flexibility and scalability of REST API make it an excellent choice for integrating Salesforce into your applications and for performing