What are the Correct Values and Actions to Automate WordPress Blog Post Publishing in Pipedream?

This topic was automatically generated from Slack. You can find the original thread here.

I’ve been exploring Pipedream for a few days, even though I don’t have any prior experience in automation or coding. I hope you don’t mind if I ask some basic questions!

My project goal is to automate WordPress blog post publishing.

" Trigger" is when a Google Doc is moved to a file, and the file name contains “Published” at the end.

While I’ve made some progress with steps 1 and 2, I’m a bit uncertain about the values to use.

Unfortunately, steps 3, 4, and 5 are a bit fuzzy for me, and I’m not sure what actions to take. I’ve attached some images to show each step and any error messages I’ve come across.

I’d really appreciate your friendly insights to help me use Pipedream more effectively.

I’m working on something similar.

Are you hosting using WORDPRESS?

First, I wouldn’t trigger from the value of Published.

I would trigger from when the file hits the folder.

You don’t want to risk your automation running every time a change is made to the folder.

why are you using an HTTP call? I’m curious.

It’s not wordpress.com. It’s wordpress.org and hosted by rocket.net

How do you achieve “trigger from when the file hits the folder” ?

Using HTTP, I just wing it. I’d love to listen to your insight.

I would use the trigger > GOOGLE DRIVE > New or Modified Folders.

, My trigger was Google Drive > New or Modified Folders, as in the attached image. I added a filter, “published,” on 2nd step.

Steps 3 and 4 are not sure. What would you use in steps 3 and 4 ?

The reason why I used HTTP was to convert the File URL to a rich-text format link.

In this case, how do the image and text reserve format when it is auto-published on a WordPress blog (not a static page)?

I’d like to know your opinion.

I am still trying to figure out how to push from Google Docs into Wordpress.

I am considering just connecting MySQL and inserting the data automatically.

I’ve never really used the Wordpress REST API.

@U05A7KLNALC

Does Pipedream use the Wordpress REST API?

Yes, Pipedream can interact with the WordPress REST API. You can use the axios package from @pipedream/platform to make HTTP requests to the WordPress REST API within a Pipedream component. Here’s an example of how to create a new post using the WordPress REST API: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { wordpressDomain: { type: "string", label: "WordPress Domain", }, username: { type: "string", label: "WordPress Username", }, password: { type: "string", label: "WordPress Password", }, postTitle: { type: "string", label: "Post Title", }, postContent: { type: "string", label: "Post Content", }, }, async run({ steps, $ }) { const authToken = Buffer.from(`${this.username}:${this.password}`).toString("base64"); return await axios($, { method: "POST", url: `https://${this.wordpressDomain}/wp-json/wp/v2/posts`, headers: { Authorization: `Basic ${authToken}`, "Content-Type": "application/json", }, data: { title: this.postTitle, content: this.postContent, status: "publish", }, }); }, }); Replace the wordpressDomain, username, password, postTitle, and postContent props with your own values. This component will create a new post on your WordPress site using the provided information.

, what should I replace postContent? My content is long-form. Did you mean that I should copy and paste the long article?

Can I also make an automation step to extract postTitle and postContent from Google Sheets or Docs?

You don’t need to copy and paste the long article directly into the postContent prop. Instead, you can extract the post title and content from Google Sheets or Google Docs using Pipedream components. For Google Sheets, you can use the “Get Row” or “Get Rows” action to retrieve the data from a specific sheet. For Google Docs, you can use the Google Docs API to fetch the content of the document. Here’s an example of how to get the content of a Google Doc and use it as the postContent: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, docId: { type: "string", label: "Google Doc ID", }, wordpressDomain: { type: "string", label: "WordPress Domain", }, username: { type: "string", label: "WordPress Username", }, password: { type: "string", label: "WordPress Password", }, postTitle: { type: "string", label: "Post Title", }, }, async run({ $ }) { // Get the content of the Google Doc const response = await axios($, { method: "GET", url: `https://docs.googleapis.com/v1/documents/${this.docId}`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, }); const postContent = response.data.body.content.map((element) => element.paragraph.elements[0].textRun.content).join("\n"); // Create a new post on WordPress const authToken = Buffer.from(`${this.username}:${this.password}`).toString("base64"); return await axios($, { method: "POST", url: `https://${this.wordpressDomain}/wp-json/wp/v2/posts`, headers: { Authorization: `Basic ${authToken}`, "Content-Type": "application/json", }, data: { title: this.postTitle, content: postContent, status: "publish", }, }); }, }); Replace the docId, wordpressDomain, username, password, and postTitle props with your own values. This component will fetch the content

You said, “You can use the axios package from @pipedream/platform to make HTTP requests to the WordPress REST API within a Pipedream component.”

Can you explain how to do it step-by-step? What step should I use axios package? Where and how should I use it?

FYI: My trigger was Google Drive > New or Modified Folders, as in the attached image. I added a filter, “published,” on 2nd step.

Do you want me to make HTTP requests on Step 3?

How do I connect it with my WordPress Rest API?

Yes, you can make an HTTP request to the WordPress REST API using the axios package from @pipedream/platform in Step 3. Here’s a step-by-step guide: 1. Add a new action step after the filter step in your workflow. 2. Choose “Run Node.js code” for the action. 3. In the code editor, paste the following code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { wordpressDomain: { type: "string", label: "WordPress Domain", }, username: { type: "string", label: "WordPress Username", }, password: { type: "string", label: "WordPress Password", }, postTitle: { type: "string", label: "Post Title", }, postContent: { type: "string", label: "Post Content", }, }, async run({ $ }) { const authToken = Buffer.from(`${this.username}:${this.password}`).toString("base64"); return await axios($, { method: "POST", url: `https://${this.wordpressDomain}/wp-json/wp/v2/posts`, headers: { Authorization: `Basic ${authToken}`, "Content-Type": "application/json", }, data: { title: this.postTitle, content: this.postContent, status: "publish", }, }); }, }); 4. Replace the wordpressDomain, username, password, postTitle, and postContent props with your own values. You can use data from previous steps, like the Google Drive trigger or the filter step, by accessing them using steps.<step_name>.<property>. 5. Deploy the workflow. This code will make an HTTP POST request to the WordPress REST API to create a new post with the provided title and content. The axios package is used to make the request, and the necessary authentication headers are included.

This is the step 3. I have got an error message. Please check the following message and let me know how I fix it. [Code Error
Unexpected token (30:32)
DETAILS

SyntaxError: Unexpected token (30:32)
    at pp$4.raise (/var/task/node_modules/acorn/dist/acorn.js:2927:15)
    at pp.unexpected (/var/task/node_modules/acorn/dist/acorn.js:698:10)
    at pp.expect (/var/task/node_modules/acorn/dist/acorn.js:692:28)
    at pp$3.parseTemplate (/var/task/node_modules/acorn/dist/acorn.js:2542:12)
    at pp$3.parseExprAtom (/var/task/node_modules/acorn/dist/acorn.js:2316:19)
    at anonymous.parseExprAtom (/var/task/node_modules/acorn-node/lib/dynamic-import/index.js:77:117)
    at anonymous.parseExprAtom (/var/task/node_modules/acorn-node/lib/import-meta/index.js:27:102)
    at pp$3.parseExprSubscripts (/var/task/node_modules/acorn/dist/acorn.js:2129:21)
    at pp$3.parseMaybeUnary (/var/task/node_modules/acorn/dist/acorn.js:2106:19)
    at anonymous.parseMaybeUnary (/var/task/node_modules/acorn-node/lib/private-class-elements/index.js:122:54)

RESULTS

Warning (likely out of date)
These results are likely out of date. Test this step again
Error
getaddrinfo ENOTFOUND https

I apologize for the confusion. It seems there’s an issue with the code provided. Please share the code you used in Step 3, so I can help you identify and fix the error.

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    wordpressDomain: {
      type: "string",
      label: "WordPress Domain",
    },
    username: {
      type: "string",
      label: "WordPress Username",
    },
    password: {
      type: "string",
      label: "WordPress Password",
    },
    postTitle: {
      type: "string",
      label: "Post Title",
    },
    postContent: {
      type: "string",
      label: "Post Content",
    },
  },
  async run({ $ }) {
    const authToken = Buffer.from(`${this.username}:${this.password}`).toString("base64");
    return await axios($, {
      method: "POST",
      url: `https://${this.wordpressDomain}/wp-json/wp/v2/posts`,
      headers: {
        Authorization: `Basic ${authToken}`,
        "Content-Type": "application/json",
      },
      data: {
        title: this.postTitle,
        content: this.postContent,
        status: "publish",
      },
    });
  },
});

Previous message was the code that I used on step3.

I’ve reviewed the code you provided, and it seems to be correct. The error message you shared earlier doesn’t seem to be directly related to this code. Can you please provide more information about the error or the context in which this code is being used? This will help me better understand the issue and provide a solution.

, can you see image?

I’m sorry, but I cannot see or process images. Please provide any relevant information in text format, and I’ll do my best to help you.