diff --git a/packages/nodes-base/credentials/ContentfulDeliveryApi.credentials.ts b/packages/nodes-base/credentials/ContentfulDeliveryApi.credentials.ts index ce620fcdb..d9078f0cc 100644 --- a/packages/nodes-base/credentials/ContentfulDeliveryApi.credentials.ts +++ b/packages/nodes-base/credentials/ContentfulDeliveryApi.credentials.ts @@ -9,13 +9,22 @@ export class ContentfulDeliveryApi implements ICredentialType { name: 'space_id', type: 'string' as NodePropertyTypes, default: '', + required: true, description: 'The id for the Cotentful space.' }, { - displayName: 'Access Token', + displayName: 'Content Delivery API - access token', name: 'access_token', type: 'string' as NodePropertyTypes, default: '', + required: true, + description: 'Access token that has access to the space' + }, + { + displayName: 'Content Preview API - access token', + name: 'access_token_preview', + type: 'string' as NodePropertyTypes, + default: '', description: 'Access token that has access to the space' } ]; diff --git a/packages/nodes-base/nodes/Contentful/ GenericFunctions.ts b/packages/nodes-base/nodes/Contentful/ GenericFunctions.ts index c59bab144..246c43c22 100644 --- a/packages/nodes-base/nodes/Contentful/ GenericFunctions.ts +++ b/packages/nodes-base/nodes/Contentful/ GenericFunctions.ts @@ -18,11 +18,22 @@ export const contentfulApiRequest = async ( throw new Error('No credentials got returned!'); } - let url = `https://cdn.contentful.com/spaces/${credentials.space_id}`; + const source = that.getNodeParameter('source', 0) as string; + const isPreview = source === 'preview_api'; + let accessToken = credentials.access_token as string; + if (isPreview) { + accessToken = credentials.access_token_preview as string; + console.log('accessToken', accessToken); + if (!accessToken) { + throw new Error('No access token for preview API set in credentials!'); + } + } + + let url = `https://${isPreview ? 'preview' : 'cdn'}.contentful.com/spaces/${credentials.space_id}`; if (environmentId) url = `${url}/environments/${environmentId}`; if (endpoint) url = `${url}${endpoint}`; qs = qs || {}; - qs.access_token = credentials.access_token as string; + qs.access_token = accessToken; const res = await that.helpers.request!({ url, diff --git a/packages/nodes-base/nodes/Contentful/Contentful.node.ts b/packages/nodes-base/nodes/Contentful/Contentful.node.ts index 866cddb26..e16fb51f2 100644 --- a/packages/nodes-base/nodes/Contentful/Contentful.node.ts +++ b/packages/nodes-base/nodes/Contentful/Contentful.node.ts @@ -33,11 +33,28 @@ export class Contentful implements INodeType { ], properties: [ // Common fields: + { + displayName: 'Source', + name: 'source', + type: 'options' as NodePropertyTypes, + default: 'Delivery API', + description: 'Pick where your data comes from, delivery or preview API', + options: [ + { + name: 'Delivery API', + value: 'delivery_api' + }, + { + name: 'Preview API', + value: 'preview_api' + } + ] + }, { displayName: 'Environment Id', name: 'environment_id', type: 'string' as NodePropertyTypes, - default: 'master', + default: '', description: 'The id for the Contentful environment (e.g. master, staging, etc.). Depending on your plan, you might not have environments. In that case use "master".' },