Calling a Lightroom API
As described elsewhere, applications must acquire an API key by registering an integration as an Adobe partner. Using the API key to authenticate a Lightroom customer with the Adobe Identity Management System enables the application to acquire an access token.
The API key must be included in the X-API-Key header in every API call, while the access token must be included in the Authorization: Bearer header.
Sample cURL for calling an API might be:
key=ClientAPIKey
token=eyJ4NXUi...
curl -H "X-API-Key: ${key}" -H "Authorization: Bearer ${token}" https://lr.adobe.io/v2/...
and sample JavaScript might be:
var key='ClientAPIKey'
var token='eyJ4NXUi...'
var xhr = new XMLHttpRequest()
xhr.open('GET', apiURL)
xhr.setRequestHeader('X-API-Key', key)
xhr.setRequestHeader('Authorization', `Bearer ${token}`)
Content Type
Lightroom content is encapsulated in a variety of objects, including accounts, catalogs, assets, and albums. The content type of every API is JSON, with the exception of the APIs that handle binary data (content type application/octet-stream) and those that handle external XMP Develop Settings (content type application/rdf+xml).
Handling JSON
Returned JSON content is always prepended with a while(1){} clause to mitigate abuse. This clause must be stripped by client applications before using the incoming result.
Sample JavaScript for eliding the preface and constructing an object might be:
function _processJSONResponse(response) {
let while1Regex = /^while\s*\(\s*1\s*\)\s*{\s*}\s*/
return response ? JSON.parse(response.replace(while1Regex, '')) : null
}