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.
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.
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
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.
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.