@contentful/app-action-utils
v1.4.1
Published
Utilities for intearcting with Hosted App Actions
Downloads
114,351
Keywords
Readme
Utils package for App Actions
This repo is a growing collection of utils for interacting with App Actions
Installation
npm install --save @contentful/app-action-utils
# or
yarn add @contentful/app-action-utils
Available features
Right now it only supports calling the app action and retrieving the result. This consist of:
- Calling app actions
- Getting an app action result
- Polling, retrying and parsing of the details call
Requirements
When passing the plain client generated from contentful-management
, it has to have org
, space
and environment
set as defaults. If not you can pass in the spaceId
and environmentId
to each of the methods.
Usage
Calling an app action and getting the result
To call an app action and get the result callAppAction
can be used like this
import { createClient } from 'contentful-management'
const api = createClient({
accessToken: '<token>'
}, {
type: 'plain'
})
const parameters: AppActionCategoryParams<'<appActionCategory>'> = {} // The parameters the app action expects, when the generic is correct it will be fully typed
const abortController = new AbortController()
const additionalParameters = {
spaceId: '<spaceId>',
environmentId: '<environmentId>'
}
const appActionResult = await callAppAction({
api,
appActionId: '<appActionId>',
appDefinitionId: '<appDefinitionId>',
parameters,
})
Getting the result of a previous call
const appActionResult = await callAppActionResult({
api,
appActionId: '<appActionId>',
callId: '<callId>',
spaceId: '<spaceId>',
environmentId: '<environmentId>'
})