This topic was automatically generated from Slack. You can find the original thread here.
Good morning. Hope all is well.
Recently, I figured out how to use the Wordpress REST API to pull a post from one site. The name of my step is called code_pull
. Here is the code:
import { axios } from "@pipedream/platform";
export default {
props: {
sourceSiteUrl: {
type: "string",
label: "Source Site URL",
description: "The URL of the Wordpress site you want to pull posts from",
},
sourceSiteUsername: {
type: "string",
label: "Source Site Username",
description: "The username for the source Wordpress site",
},
sourceSitePassword: {
type: "string",
label: "Source Site Password",
description: "The password for the source Wordpress site",
},
postId: {
type: "integer",
label: "Post ID",
description: "The ID of the post you want to pull from the source site",
},
},
async run({ $ }) {
const postResponse = await axios($, {
method: "GET",
url: `${this.sourceSiteUrl}/wp-json/wp/v2/posts/${this.postId}?context=edit`,
auth: {
username: this.sourceSiteUsername,
password: this.sourceSitePassword,
},
});
const commentsResponse = await axios($, {
method: "GET",
url: `${this.sourceSiteUrl}/wp-json/wp/v2/comments`,
params: {
post: this.postId,
},
auth: {
username: this.sourceSiteUsername,
password: this.sourceSitePassword,
},
});
return {
post: postResponse,
comments: commentsResponse,
};
},
};
Are you can see it was modified to fetch the post data with the raw post_content
field and the associated comments.
I would like you to write me a code that will request the target site URL, target site Username and target site Password.
The goal is to push the object into the other Wordpress using the raw post_content that contains the associated comments.