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
| Function | Endpoint | Returns |
|---|---|---|
fetchProject(apiUrl, projectId, options?) | Project config | Promise<ProjectConfig | null> |
fetchExperienceContent(apiUrl, projectId, experienceId, options?) | Experience content | Promise<ExperienceContentResponse | null> |
fetchSchema(apiUrl, projectId, options?) | Workspace schema | Promise<WorkspaceSchema | null> |
runAction(apiUrl, payload, options?) | POST /api/v1/action/<key>/run | Promise<RunActionResult> |
createClientHeaders(name, version) | none | The Picked-Client and Picked-Version headers. |
apiUrl is the origin of the API, for example https://api.picked.app.
Options
| Option | Type | Description |
|---|---|---|
previewToken | string | Reads the draft of a workspace. See Preview. |
headers | Record<string, string> | More request headers. |
signal | AbortSignal | Stops the request. |
onWarn | (message: string, error?: unknown) => void | Receives each failure of a fetch function. |
onResponse | (status: number) => void | Receives the HTTP status of fetchProject and fetchExperienceContent. |
runAction takes only previewToken, headers and signal.
Errors
Each request stops after 10 seconds.
| Function | On failure |
|---|---|
fetchProject, fetchExperienceContent, fetchSchema | Returns 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. |
runAction | Throws an Error for a status that is not ok. |
