n8n-nodes-base
Version:
Base nodes of n8n
33 lines • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mediumApiRequest = mediumApiRequest;
const n8n_workflow_1 = require("n8n-workflow");
async function mediumApiRequest(method, endpoint, body = {}, query = {}, uri) {
const authenticationMethod = this.getNodeParameter('authentication', 0);
const options = {
method,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Accept-Charset': 'utf-8',
},
qs: query,
uri: uri || `https://api.medium.com/v1${endpoint}`,
body,
json: true,
};
try {
if (authenticationMethod === 'accessToken') {
const credentials = await this.getCredentials('mediumApi');
options.headers.Authorization = `Bearer ${credentials.accessToken}`;
return await this.helpers.request(options);
}
else {
return await this.helpers.requestOAuth2.call(this, 'mediumOAuth2Api', options);
}
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
//# sourceMappingURL=GenericFunctions.js.map