I am getting the following error:
Error - Request failed with status code 401
{"status":"error","error":"MISSING_AUTHORIZATION_HEADER","code":"401","error_description":"Authorization header not received. Either authorization header was not sent or it was removed by your server due to security reasons."}
Please rewrite the following code so we can determine where the code is failing?
import { axios } from "@pipedream/platform";
import { Buffer } from 'buffer';
export default {
props: {
rssUrl: {
type: "string",
label: "RSS Feed URL",
},
sourceWordpressUrl: {
type: "string",
label: "Source WordPress Site URL",
},
targetWordpressUrl: {
type: "string",
label: "Target WordPress Site URL",
},
username: {
type: "string",
label: "Username for Target WordPress Site",
},
password: {
type: "string",
label: "Password for Target WordPress Site",
},
},
async run({ $ }) {
// Extract post ID from the RSS feed update
const postId = this.rssUrl.split('/').pop();
// Fetch the post data from the source WordPress site
const sourceUrl = `${this.sourceWordpressUrl}/wp-json/wp/v2/posts/${postId}`;
const sourceResponse = await axios($, {
method: "GET",
url: sourceUrl,
});
// Prepare the post data for the target WordPress site
const targetUrl = `${this.targetWordpressUrl}/wp-json/wp/v2/posts`;
const credentials = Buffer.from(`${this.username}:${this.password}`).toString('base64');
const data = {
title: sourceResponse.title.rendered,
content: sourceResponse.content.rendered,
status: 'publish',
};
// Push the post data to the target WordPress site
const targetResponse = await axios($, {
method: "POST",
url: targetUrl,
headers: {
'Authorization': `Basic ${credentials}`,
},
data: data,
});
return targetResponse;
},
};