2022-08-17 08:50:24 -07:00
|
|
|
import { OptionsWithUrl } from 'request';
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
2021-04-16 09:33:36 -07:00
|
|
|
import { NodeApiError } from 'n8n-workflow';
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
export async function linkedInApiRequest(
|
|
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
|
|
method: string,
|
|
|
|
endpoint: string,
|
2022-12-02 06:25:21 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
body: any = {},
|
|
|
|
binary?: boolean,
|
2022-11-08 06:28:21 -08:00
|
|
|
_headers?: object,
|
2022-08-17 08:50:24 -07:00
|
|
|
): Promise<any> {
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
const options: OptionsWithUrl = {
|
|
|
|
headers: {
|
2022-08-17 08:50:24 -07:00
|
|
|
Accept: 'application/json',
|
2020-10-22 06:46:03 -07:00
|
|
|
'X-Restli-Protocol-Version': '2.0.0',
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
},
|
|
|
|
method,
|
|
|
|
body,
|
|
|
|
url: binary ? endpoint : `https://api.linkedin.com/v2${endpoint}`,
|
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
// If uploading binary data
|
|
|
|
if (binary) {
|
|
|
|
delete options.json;
|
|
|
|
options.encoding = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object.keys(body).length === 0) {
|
|
|
|
delete options.body;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-08-17 08:50:24 -07:00
|
|
|
return await this.helpers.requestOAuth2!.call(this, 'linkedInOAuth2Api', options, {
|
|
|
|
tokenType: 'Bearer',
|
|
|
|
});
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
} catch (error) {
|
2021-04-16 09:33:36 -07:00
|
|
|
throw new NodeApiError(this.getNode(), error);
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
export function validateJSON(json: string | undefined): any {
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
let result;
|
|
|
|
try {
|
|
|
|
result = JSON.parse(json!);
|
|
|
|
} catch (exception) {
|
|
|
|
result = '';
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|