mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add parameter to include credentials in querystring (Woocommerce) (#1756)
This commit is contained in:
parent
7bc79c879d
commit
c632f7982f
|
@ -27,5 +27,14 @@ export class WooCommerceApi implements ICredentialType {
|
||||||
default: '',
|
default: '',
|
||||||
placeholder: 'https://example.com',
|
placeholder: 'https://example.com',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Include Credentials in Query',
|
||||||
|
name: 'includeCredentialsInQuery',
|
||||||
|
type: 'boolean' as NodePropertyTypes,
|
||||||
|
default: false,
|
||||||
|
description: `Occasionally, some servers may not parse the Authorization header correctly</br>
|
||||||
|
(if you see a “Consumer key is missing” error when authenticating over SSL, you have a server issue).</br>
|
||||||
|
In this case, you may provide the consumer key/secret as query string parameters instead.`,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IWebhookFunctions,
|
IWebhookFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ICredentialDataDecryptedObject,
|
ICredentialDataDecryptedObject,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
|
@ -36,6 +37,7 @@ export async function woocommerceApiRequest(this: IHookFunctions | IExecuteFunct
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||||
}
|
}
|
||||||
|
|
||||||
let options: OptionsWithUri = {
|
let options: OptionsWithUri = {
|
||||||
auth: {
|
auth: {
|
||||||
user: credentials.consumerKey as string,
|
user: credentials.consumerKey as string,
|
||||||
|
@ -47,11 +49,16 @@ export async function woocommerceApiRequest(this: IHookFunctions | IExecuteFunct
|
||||||
uri: uri || `${credentials.url}/wp-json/wc/v3${resource}`,
|
uri: uri || `${credentials.url}/wp-json/wc/v3${resource}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (credentials.includeCredentialsInQuery === true) {
|
||||||
|
delete options.auth;
|
||||||
|
Object.assign(qs, { consumer_key: credentials.consumerKey, consumer_secret: credentials.consumerSecret });
|
||||||
|
}
|
||||||
|
|
||||||
if (!Object.keys(body).length) {
|
if (!Object.keys(body).length) {
|
||||||
delete options.form;
|
delete options.form;
|
||||||
}
|
}
|
||||||
options = Object.assign({}, options, option);
|
options = Object.assign({}, options, option);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -367,7 +367,7 @@ export class WooCommerce implements INodeType {
|
||||||
//https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product
|
//https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product
|
||||||
if (operation === 'get') {
|
if (operation === 'get') {
|
||||||
const productId = this.getNodeParameter('productId', i) as string;
|
const productId = this.getNodeParameter('productId', i) as string;
|
||||||
responseData = await woocommerceApiRequest.call(this,'GET', `/products/${productId}`, {}, qs);
|
responseData = await woocommerceApiRequest.call(this, 'GET', `/products/${productId}`, {}, qs);
|
||||||
}
|
}
|
||||||
//https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-products
|
//https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-products
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
|
@ -434,7 +434,7 @@ export class WooCommerce implements INodeType {
|
||||||
//https://woocommerce.github.io/woocommerce-rest-api-docs/#delete-a-product
|
//https://woocommerce.github.io/woocommerce-rest-api-docs/#delete-a-product
|
||||||
if (operation === 'delete') {
|
if (operation === 'delete') {
|
||||||
const productId = this.getNodeParameter('productId', i) as string;
|
const productId = this.getNodeParameter('productId', i) as string;
|
||||||
responseData = await woocommerceApiRequest.call(this,'DELETE', `/products/${productId}`, {}, { force: true });
|
responseData = await woocommerceApiRequest.call(this, 'DELETE', `/products/${productId}`, {}, { force: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resource === 'order') {
|
if (resource === 'order') {
|
||||||
|
@ -583,7 +583,7 @@ export class WooCommerce implements INodeType {
|
||||||
//https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-an-order
|
//https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-an-order
|
||||||
if (operation === 'get') {
|
if (operation === 'get') {
|
||||||
const orderId = this.getNodeParameter('orderId', i) as string;
|
const orderId = this.getNodeParameter('orderId', i) as string;
|
||||||
responseData = await woocommerceApiRequest.call(this,'GET', `/orders/${orderId}`, {}, qs);
|
responseData = await woocommerceApiRequest.call(this, 'GET', `/orders/${orderId}`, {}, qs);
|
||||||
}
|
}
|
||||||
//https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-orders
|
//https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-orders
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
|
@ -629,7 +629,7 @@ export class WooCommerce implements INodeType {
|
||||||
//https://woocommerce.github.io/woocommerce-rest-api-docs/#delete-an-order
|
//https://woocommerce.github.io/woocommerce-rest-api-docs/#delete-an-order
|
||||||
if (operation === 'delete') {
|
if (operation === 'delete') {
|
||||||
const orderId = this.getNodeParameter('orderId', i) as string;
|
const orderId = this.getNodeParameter('orderId', i) as string;
|
||||||
responseData = await woocommerceApiRequest.call(this,'DELETE', `/orders/${orderId}`, {}, { force: true });
|
responseData = await woocommerceApiRequest.call(this, 'DELETE', `/orders/${orderId}`, {}, { force: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Array.isArray(responseData)) {
|
if (Array.isArray(responseData)) {
|
||||||
|
|
Loading…
Reference in a new issue