mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user