Skip to content
LogoLogo

Delivery API client

@picked/delivery-api-client gives typed functions for the Delivery API. The Picked SDK uses it, and you can use it on a server or in a script.

import { fetchExperienceContent, fetchProject, fetchSchema } from '@picked/delivery-api-client'
 
const config = await fetchProject('https://api.picked.app', 'your-project-id')
const content = await fetchExperienceContent(
  'https://api.picked.app',
  'your-project-id',
  'your-experience-id',
)
const schema = await fetchSchema('https://api.picked.app', 'your-project-id')

Functions

FunctionEndpointReturns
fetchProject(apiUrl, projectId, options?)Project configPromise<ProjectConfig | null>
fetchExperienceContent(apiUrl, projectId, experienceId, options?)Experience contentPromise<ExperienceContentResponse | null>
fetchSchema(apiUrl, projectId, options?)Workspace schemaPromise<WorkspaceSchema | null>
runAction(apiUrl, payload, options?)POST /api/v1/action/<key>/runPromise<RunActionResult>
createClientHeaders(name, version)noneThe Picked-Client and Picked-Version headers.

apiUrl is the origin of the API, for example https://api.picked.app.

Options

OptionTypeDescription
previewTokenstringReads the draft of a workspace. See Preview.
headersRecord<string, string>More request headers.
signalAbortSignalStops the request.
onWarn(message: string, error?: unknown) => voidReceives each failure of a fetch function.
onResponse(status: number) => voidReceives the HTTP status of fetchProject and fetchExperienceContent.

runAction takes only previewToken, headers and signal.

Errors

Each request stops after 10 seconds.

FunctionOn failure
fetchProject, fetchExperienceContent, fetchSchemaReturns null and calls onWarn. A failure is a network error, a status that is not ok, a body that is not JSON, or a body with the wrong shape.
runActionThrows an Error for a status that is not ok.