mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
feat(LinkedIn Node): Add support for Community Management API (#7451)
This commit is contained in:
@@ -25,6 +25,14 @@ export async function linkedInApiRequest(
|
||||
binary?: boolean,
|
||||
_headers?: object,
|
||||
): Promise<any> {
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||
const credentialType =
|
||||
authenticationMethod === 'standard'
|
||||
? 'linkedInOAuth2Api'
|
||||
: 'linkedInCommunityManagementOAuth2Api';
|
||||
|
||||
const baseUrl = 'https://api.linkedin.com';
|
||||
|
||||
let options: OptionsWithUrl = {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
@@ -33,9 +41,10 @@ export async function linkedInApiRequest(
|
||||
},
|
||||
method,
|
||||
body,
|
||||
url: binary ? endpoint : `https://api.linkedin.com/rest${endpoint}`,
|
||||
url: binary ? endpoint : `${baseUrl}${endpoint.includes('v2') ? '' : '/rest'}${endpoint}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
options = Object.assign({}, options, {
|
||||
resolveWithFullResponse: true,
|
||||
});
|
||||
@@ -51,7 +60,7 @@ export async function linkedInApiRequest(
|
||||
|
||||
try {
|
||||
return resolveHeaderData(
|
||||
await this.helpers.requestOAuth2.call(this, 'linkedInOAuth2Api', options, {
|
||||
await this.helpers.requestOAuth2.call(this, credentialType, options, {
|
||||
tokenType: 'Bearer',
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -28,9 +28,39 @@ export class LinkedIn implements INodeType {
|
||||
{
|
||||
name: 'linkedInOAuth2Api',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: ['standard'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'linkedInCommunityManagementOAuth2Api',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: ['communityManagement'],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Authentication',
|
||||
name: 'authentication',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Standard',
|
||||
value: 'standard',
|
||||
},
|
||||
{
|
||||
name: 'Community Management',
|
||||
value: 'communityManagement',
|
||||
},
|
||||
],
|
||||
default: 'standard',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
@@ -55,12 +85,24 @@ export class LinkedIn implements INodeType {
|
||||
// Get Person URN which has to be used with other LinkedIn API Requests
|
||||
// https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin
|
||||
async getPersonUrn(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const person = await linkedInApiRequest.call(this, 'GET', '/me', {});
|
||||
returnData.push({
|
||||
name: `${person.localizedFirstName} ${person.localizedLastName}`,
|
||||
value: person.id,
|
||||
});
|
||||
const authentication = this.getNodeParameter('authentication', 0);
|
||||
let endpoint = '/me';
|
||||
if (authentication === 'standard') {
|
||||
const { legacy } = await this.getCredentials('linkedInOAuth2Api');
|
||||
if (!legacy) {
|
||||
endpoint = '/v2/userinfo';
|
||||
}
|
||||
}
|
||||
const person = await linkedInApiRequest.call(this, 'GET', endpoint, {});
|
||||
const firstName = person.localizedFirstName ?? person.given_name;
|
||||
const lastName = person.localizedLastName ?? person.family_name;
|
||||
const name = `${firstName} ${lastName}`;
|
||||
const returnData: INodePropertyOptions[] = [
|
||||
{
|
||||
name,
|
||||
value: person.id ?? person.sub,
|
||||
},
|
||||
];
|
||||
return returnData;
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user