fix(LinkedIn Node): Update the version of the API (#5720)

* 🐛 Change request to follow new API version

* Extract urn from response header

* Change body params for image and media request

* Fix body for Image and Article posts

* remove console log

---------

Co-authored-by: Marcus <marcus@n8n.io>
This commit is contained in:
agobrech
2023-03-31 15:04:43 +02:00
committed by GitHub
parent 97b35daf0a
commit 18d2e7cd57
2 changed files with 53 additions and 92 deletions

View File

@@ -8,6 +8,13 @@ import type {
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
function resolveHeaderData(fullResponse: any) {
if (fullResponse.statusCode === 201) {
return { urn: fullResponse.headers['x-restli-id'] };
} else {
return fullResponse.body;
}
}
export async function linkedInApiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
@@ -18,17 +25,20 @@ export async function linkedInApiRequest(
binary?: boolean,
_headers?: object,
): Promise<any> {
const options: OptionsWithUrl = {
let options: OptionsWithUrl = {
headers: {
Accept: 'application/json',
'X-Restli-Protocol-Version': '2.0.0',
'LinkedIn-Version': '202301',
},
method,
body,
url: binary ? endpoint : `https://api.linkedin.com/v2${endpoint}`,
url: binary ? endpoint : `https://api.linkedin.com/rest${endpoint}`,
json: true,
};
options = Object.assign({}, options, {
resolveWithFullResponse: true,
});
// If uploading binary data
if (binary) {
delete options.json;
@@ -40,9 +50,11 @@ export async function linkedInApiRequest(
}
try {
return await this.helpers.requestOAuth2.call(this, 'linkedInOAuth2Api', options, {
tokenType: 'Bearer',
});
return resolveHeaderData(
await this.helpers.requestOAuth2.call(this, 'linkedInOAuth2Api', options, {
tokenType: 'Bearer',
}),
);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}