mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
Handle preview api
This commit is contained in:
parent
fa0e8c84f5
commit
1a785581ff
|
@ -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'
|
||||
}
|
||||
];
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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".'
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue