Badge-A-Day: API Basics

API Basics.JPG

On today's badge-a-day challenge, I tackle the API Basics badge! *Cue dramatic music*

This is the part of my architect journey where concepts start leaning heavily into the developer's wheelhouse, a place where I'm not nearly as comfortable as system administration and solution design. Luckily for me, Salesforce nobody has better resources or a more engaged community than Salesforce! 

Get to Know the Salesforce APIs

  • Salesforce takes an API-first approach to building features on the Salesforce platform.
  • API first means building a robust API for a feature before focusing on designing its UI.

Salesforce Data APIs

  • The commonly used APIs are REST, SOAP, Bulk, and Streaming API.

REST API

  • REST API is a simple and powerful web service based on RESTful principles. It exposes all sorts of Salesforce functionality via REST resources and HTTP methods.
  • Example: CRUD records, search or query data, retrieve object metadata, and access information about limits in your org.
  • REST API supports JSON and XML.

SOAP API

  • SOAP API is a robust and powerful web service based on the industry standard protocol of the same name.
  • It uses a web services description language (WSDL) file to define parameters for accessing data through the API.
  • SOAP supports XML only.
  • SOAP API uses the WSDL file as a formal contract between the API and consumer, so it is great for server-to-server integrations.

Bulk API

  • Bulk API is a specialized RESTful API for loading and querying 50,000 records or more at once.
  • Bulk API is asynchronous, meaning that you can submit a request and come back later for the results.

Streaming API

  • Streaming API is a specialized API for setting up notifications that trigger when changes are made to your data.
  • It uses publish-subscribe, or pub/sub, in which users can subscribe to channels that broadcast certain types of data changes.
  • Pub/Sub reduces the API requests by eliminating the need for polling.
  • Streaming is great for apps that would otherwise need to frequently poll for changes.

API Access and Authentication

  • All API calls, except for the SOAP API login() call, require authentication.
  • You can either use a supported OAuth flows or authenticate with a Session ID retrieved from the SOAP API login() call.

API Limits

  • Salesforce limits the number of API calls per org to ensure the health of the instance.
  • These limits exist to prevent rogue scripts from hogging resources.
  • There are two types of limits: concurrent limits cap the number of long-running calls (20 seconds or longer) that are running at one time. Total limits cap the number of calls made within a rolling 24-hour period.
  • Concurrent limits vary by org type.
  • Total limits vary by org edition, license type, and expansion packs purchased.
  • Check API calls in System Overview or API Usage notifications.

When to use REST API

  • Easy to integrate and develop, REST is an excellent choice for mobile and web projects.

When to use SOAP API

  • Use SOAP to create, retrieve, update, or delete records.
  • You can also use SOAP to perform searches.
  • Use SOAP in any language that supports web services.

When to use Chatter REST API

  • Use it Chatter REST API to display Chatter feeds, users, groups, and followers, especially in mobile applications.
  • It also provides programmatic access to files, recommendations, topics, notifications, Data.com purchasing, and more.

When to use User Interface API

  • Build Salesforce UI for native mobile apps and custom web apps using the same API that Salesforce uses to build lightning experience and Salesforce for Android, iOS, and mobile web.
  • Users can work with records, list views, actions, favorites, and more.
  • Get data and metadata in a single response.

When to use Analytics REST API

  • Use Analytics REST API to access analytics assets such as datasets, lenses, and dashboards.
  • Send queries directly to the Analytics platform.
  • Access datasets that have been imported into the Analytics Platform.

When to use Bulk API

  • Use Bulk API when loading large data volumes.
  • Turn on Bulk API in Data loader.

When to use Metadata API

  • Retrieve, deploy, create, update, or delete customization in your org.
  • When migrating changes from sandbox to production.
  • Intended for managing customizations and for building tools that can manage the metadata model, not the data itself.
  • Use the force.com IDE or Ant Migration Tool.

When to use Streaming API

  • When you need to receive near real time streams of data that are based on changes in Salesforce records or custom payloads.

When to use Apex REST API

  • When you want to expose your Apex classes and methods so that external applications can access your code through REST architecture.

When to use Apex SOAP API

  • When you want to expose Apex methods as a SOAP webs service APIs so that external applications can access your code through SOAP.

When to use Tooling API

  • When you need to integrate Salesforce metadata with other systems.