Lightning API—Developer Preview

Use Lightning API to create native mobile apps and custom web apps with your own branding and look and feel. A single REST request returns enough metadata, layout information, and data to display, edit, or create a record! Lightning API supports most objects that are available in Lightning Experience.
Available in: Developer Edition

Note

Note

Lightning API is available as a Developer Preview in all DE orgs. To use the API in another type of org, contact Salesforce.

Get to Know Lightning API

The Lightning API base URL is https://{your_instance}.salesforce.com/services/data/v{api_version}/lapi.
To get metadata and data to display a record, your code makes a simple REST request to a resource.
GET /lapi/record-ui/001R0000003GeJ1IAK
Behind the scenes, Salesforce does the heavy lifting.
  • Checks field-level security settings, sharing settings, and perms.
  • Makes SOQL queries to get record data.
  • Gets object metadata and theme information.
  • Gets layout information.
You are one happy developer, because Salesforce transforms the results into an easy-to-consume JSON response with all the information you need to display a record.
Tip

Tip

The Lightning API Developer Guide contains a step-by-step Quick Start to get you up and running. Here's the quick version of the Quick Start: open Workbench, log in to a DE org, and make a request to a Lightning API resource!

Authorization
Like other Salesforce REST APIs, Lightning API uses OAuth 2.0.
Versioning
Lightning API is versioned. Specify the API version number in each request.
GET https://{your_instance}.salesforce.com/services/data/v39.0/lapi
Response Filtering
Lightning API is built on the same REST framework as Chatter REST API and observes the same filtering rules.
Also, several Lightning API resources support additional parameters that change the response to include what your UI needs.
  • formFactor—The layout display size for the record.
    • Large—(Default) Use this value to get a layout for desktop display size.
    • Medium—Use this value to get a layout for tablet display size.
    • Small—Use this value to get a layout for phone display size.
  • layoutType—The layout type for the record.
    • Compact—Use this value to get a layout that contains a record's key fields.
    • Full—(Default) Use this value to get a full layout.
  • mode—The access mode for the record. This value determines which fields to get from a layout. Layouts have different fields for create, edit, and view modes. For example, formula fields are rendered in view mode, but not in create mode because they’re calculated at run time, like formulas in a spreadsheet.
    • Create—Use this mode if you intend to build UI that lets a user create a record. This mode is used by the /lapi/record-defaults/create/{apiName} resource.
    • Edit—Use this mode if you intend to build UI that lets a user edit a record. This mode is used by the /lapi/record-defaults/clone/{recordId} resource.
    • View—(Default) Use this mode if you intend to build UI that displays a record.
Error Handling
The response header contains an HTTP status code. If the response isn’t successful, the response body contains an error message, and if appropriate, information about the field or object where the error occurred.
Rate Limiting
Lightning API requests are subject to rate limiting. Lightning API has a per user, per application, per hour rate limit. When you exceed the rate limit, all Lightning API resources return a 503 Service Unavailable error code.
Required Fields
When you’re building UI, to determine which fields to mark as required for create and update, use the ObjectInfo.fields[].required property.

Resources

Record UI—GET
GET /lapi/record-ui/{recordIds}
    [?layoutTypes={layoutTypeList}&modes={modeList}
    &formFactor={formFactor}&optionalFields={fieldNameList}]
This resource is the top dog of Lightning API. Use it to get layout information, metadata, and data to build UI for a single record or for a collection of records. The response includes three nested response bodies:
  • layouts—A map of object API names to layout information for each object
  • objectInfos—A map of object API names to metadata for each object
  • records—A map of record IDs to data for each record
Record Layout—GET
GET /lapi/layout/{objectApiName}
    [?formFactor={formFactorType}&layoutType={layoutType}
    &mode={mode}&recordTypeId={recordTypeId}]
Get the layout for a specific record in a specific form factor, layout type, and mode.
The response is also the nested layouts response body returned from GET /lapi/record-ui/{recordIds}, and the nested layout response body returned from GET /lapi/record-defaults/clone/{recordId} and GET /lapi/record-defaults/create/{apiName}.
Object Info—GET
GET /lapi/object-info/{objectApiName}
    [?layoutTypes={layoutTypeList}&modes={modeList}
    &recordTypeId={recordTypeId}]
Get an object’s metadata for one or more layout types and modes.
The response is also the nested objectInfos response body returned from GET /lapi/record-ui/{recordIds}, and the nested objectInfo response body returned from GET /lapi/record-defaults/clone/{recordId} and GET /lapi/record-defaults/create/{apiName}.
Record—GET, PATCH (Update), DELETE
GET /lapi/records/{recordId}?layoutTypes={layoutTypeList}
    [&modes={modeList}&optionalFields={optionalFieldList}]

GET /lapi/records/{recordId}?fields={fieldList}[&optionalFields={optionalFieldList}]

PATCH /lapi/records/{recordId}?apiName={apiName}&fields={fieldList}

DELETE /lapi/records/{recordId}
Get, update, and delete data for a specific record.
The response is also the nested records response body returned from GET /lapi/record-ui/{recordIds}, and the nested record response body returned from GET /lapi/record-defaults/clone/{recordId} and GET /lapi/record-defaults/create/{apiName}.
Record—Batch GET
GET /lapi/records/batch/{recordIds}?layoutTypes={layoutTypeList}
    [&modes={modeList}&optionalFields={optionalFieldList}]

GET /lapi/records/batch/{recordIds}?fields={fieldList}
    [&optionalFields={optionalFieldList}]
Get data for a batch of records. The response contains record data or error information for each record in the batch.
Record—POST (Create)
POST /lapi/records

{
  "apiName": "Account",
  "fields": {
    "Name": "Universal Containers"
  }
}
Create a record.
Before you create a record, get the default values for the record. Make a request to either /lapi/record-defaults/clone/{recordId} or /lapi/record-defaults/create/{apiName}, depending on whether you want to clone an existing record or create a record.
Clone Record Defaults—GET
GET /lapi/record-defaults/clone/{recordId}[?formFactor={formFactor}&recordTypeId={recordTypeId}]
Get the default values for fields for cloning a record. After getting the default values, make a request to POST /lapi/records to create the record.
The response includes three nested response bodies.
  • layout—Layout information for the object
  • objectInfo—Metadata for the object
  • record—Data for each record
Create Record Defaults—GET
GET /lapi/record-defaults/create/{apiName}[?formFactor={formFactor}&recordTypeId={recordTypeId}]
Get the default values for fields for a new record of a particular object. After getting the default values, make a request to POST /lapi/records to create the record.
The response includes three nested response bodies.
  • layout—Layout information for the object
  • objectInfo—Metadata for the object
  • record—Data for each record
Picklist Values—GET
GET /lapi/object-info/{objectApiName}/picklist-values/{recordTypeId}/{fieldApiName}
Get the values for a picklist.
When you make a request to /lapi/record-ui/{recordIds} or /lapi/object-info/{objectApiName}, if the response includes a picklist field, it also includes a picklistValueUrl property. That property contains a Picklist Values resource with the {objectApiName}, {recordTypeId}, and {fieldApiName} filled in, such as in the following example.
GET /services/data/v39.0/lapi/object-info/Account/picklist-values/012000000000000AAA/Type/

{
  "controllerValues" : { },
  "defaultValue" : null,
  "url" : "/services/data/v39.0/lapi/object-info/Account/picklist-values/012000000000000AAA/Type",
  "values" : [ {
    "attributes" : null,
    "label" : "Analyst",
    "picklistValueType" : "Standard",
    "validFor" : [ ],
    "value" : "Analyst"
  }, {
    "attributes" : null,
    "label" : "Competitor",
    "picklistValueType" : "Standard",
    "validFor" : [ ],
    "value" : "Competitor"
  }, 

  ... some picklist values removed for space ...

  {
    "attributes" : null,
    "label" : "Other",
    "picklistValueType" : "Standard",
    "validFor" : [ ],
    "value" : "Other"
  } ]
}