Thank you for providing the link to your workflow. Unfortunately, I cannot access your workflow directly through the link. Please share the relevant code snippet and any additional details about your Pipedream workflow or the steps you were trying to perform. This will help me understand the problem better and provide you with an appropriate solution.
, My project goal is to automate WordPress blog post publishing.
Step 1: " Trigger" is when a Google Doc is moved to a file
Step 2: “Filter” is the file name containing “Published” at the end.
Step 3: extract file info from Google Doc ID
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
google: {
type: "app",
app: "google",
},
fileId: {
type: "string",
label: "Google Document File ID",
default: "YOUR_GOOGLE_DOC_FILE_ID",
},
},
async run({ $ }) {
const response = await axios($, {
method: "GET",
url: `https://www.googleapis.com/drive/v3/files/${this.fileId}/export`,
headers: {
Authorization: `Bearer ${this.google.$auth.oauth_access_token}`,
},
params: {
mimeType: "text/plain",
},
responseType: "text",
});
return { content: response.data };
},
});
Step 4: code
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
username: {
type: "string",
label: "Username",
},
password: {
type: "string",
label: "Application Password",
},
},
async run({ $ }) {
const endpoint = "https://digitaltopical.com/wp-json/wp/v2/posts";
const auth = Buffer.from(`${this.username}:${this.password}`).toString("base64");
const response = await axios($, {
method: "GET",
url: endpoint,
headers: {
Authorization: `Basic ${auth}`,
},
});
return response;
},
});
Step 5: Create a post on WordPress
I’ve got an error message on Step 5, like the following.
Error
Autodiscovery failed
DETAILS
at null.null (/tmp/__pdg__/dist/code/56ca7e151e4b14be2c03cda7230479dc5ed1888cb7f8c6bcd70e9f505d4c5750/node_modules/.pnpm/wpapi@1.2.2/node_modules/wpapi/wpapi.js:465:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at Object.getClient (file:///tmp/__pdg__/dist/code/56ca7e151e4b14be2c03cda7230479dc5ed1888cb7f8c6bcd70e9f505d4c5750/code/wordpress_org.app.mjs:164:16)
at Object.createPost (file:///tmp/__pdg__/dist/code/56ca7e151e4b14be2c03cda7230479dc5ed1888cb7f8c6bcd70e9f505d4c5750/code/wordpress_org.app.mjs:222:18)
at Object.run (file:///tmp/__pdg__/dist/code/56ca7e151e4b14be2c03cda7230479dc5ed1888cb7f8c6bcd70e9f505d4c5750/code/actions/create-post/create-post.mjs:65:18)
at null.executeComponent (/var/task/launch_worker.js:229:22)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
Detailed/code mode
Wor**dpress.org**
Account
WordPress DigitalTopical
Title
steps.step3.file
Content
steps.step3.content
<hrp-shortcut class=“hrp-container” style=“box-sizing: border-box; border-width: 0px; border-style: solid; border-color: transparent; --tw-ring-inset: var(–tw-empty, ); --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(51, 170, 255, .5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; position: fixed; bottom: 24px; right: 24px; z-index: 2147483646; opacity: 1; height: 30px; box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px; border-radius: 4px; background-color: rgb(255, 255, 255); display: flex; flex-direction: row; align-items: center; transition: box-shadow 0.15s ease-in-out 0s;”>
I see that you’re trying to automate WordPress blog post publishing using a Pipedream workflow. Based on the error message you provided, it seems like there’s an issue with the autodiscovery process in Step 5. Instead of using the autodiscovery feature, you can directly specify the WordPress API endpoint in your code. Here’s an updated version of the code for Step 5: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { wordpress_org: { type: “app”, app: “wordpress_org”, }, title: { type: “string”, label: “Post Title”, }, content: { type: “string”, label: “Post Content”, }, }, async run({ $ }) { const endpoint = “https://digitaltopical.com/wp-json/wp/v2/posts”; const auth = Buffer.from(${this.wordpress_org.$auth.username}:${this.wordpress_org.$auth.application_password}
).toString(“base64”); const response = await axios($, { method: “POST”, url: endpoint, headers: { Authorization: Basic ${auth}
, }, data: { title: this.title, content: this.content, }, }); return response; }, });
, What step should I add or override the code that you gave me in the previous conversation?
Apologies for the confusion earlier. You should replace the code in the step where you’re trying to create a new WordPress blog post. If you’re using a code step for this purpose, simply replace the existing code with the updated code I provided in my previous response. This should resolve the autodiscovery issue you were facing.
, do you want me to remove the code on step 4 and replace it with the new one?
Or do you want me to remove step 5 and create a new step 5 with the new code?
I apologize for the confusion earlier. Please remove the code in the step where you’re trying to create a new WordPress blog post (either Step 4 or Step 5, whichever is the correct step in your workflow). Replace the existing code in that step with the updated code I provided in my previous response. This should resolve the autodiscovery issue you were facing.
, stet3:Google Account
Credentials are encrypted. Revoke anytime.
Google Document File ID
{{steps}}
CODE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import
{ axios }
from
“@pipedream/platform”;
export default defineComponent({
props: {
google: {
type: “app”,
app: “google”,
},
fileId: {
type: “string”,
label: “Google Document File ID”,
default: “YOUR_GOOGLE_DOC_FILE_ID”,
},
},
async run({ steps, $ }) {
const response = await axios($, {
method: “GET”,
url: https://www.googleapis.com/drive/v3/files/${**this**.fileId}/export
,
headers: {
Authorization: Bearer ${**this**.google.$auth.oauth_access_token}
,
},
params: {
mimeType: “text/plain”,
},
responseType: “text”,
});
**return** { content: response };
},
});
RESULTS
Error - Request failed with status code 503
I apologize for the confusion in my previous responses. Based on the code you provided, it seems like you’re trying to fetch the content of a Google Document using the Google Drive API. The error you’re encountering, “Request failed with status code 503,” typically indicates a server-side issue. To help you resolve this issue, please try the following steps: 1. Make sure that your Google API credentials are correct and have the necessary permissions to access the Google Drive API. 2. Double-check the Google Document File ID to ensure it’s valid and accessible by the account you’re using. 3. It’s possible that the Google API is experiencing temporary issues. You can try running the workflow again after some time to see if the issue resolves itself. If the issue persists, please let me know, and I’ll be happy to help you further.
under configure, what should I input on Google Document File ID,?
The Google Document File ID is a unique identifier for the Google Document you want to fetch the content from. You can find the File ID in the URL of the Google Document when you have it open in your browser. The URL will look like this: https://docs.google.com/document/d/FILE_ID/edit
. Replace FILE_ID
in the code with the actual File ID from your Google Document’s URL.
, in that way, I configured the file ID manually. I wonder how the automation will happen if the other file is created? Should I type the file ID manually? If so, it is not automation.
To automate fetching content from newly created Google Documents, you can use the Google Drive API to list the files in a specific folder or with specific criteria, and then fetch the content of those files. Here’s a modified version of the component code that lists the files in a folder and fetches the content of the latest file: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, folderId: { type: "string", label: "Google Drive Folder ID", }, }, async run({ steps, $ }) { // List files in the specified folder const fileListResponse = await axios($, { method: "GET", url: "https://www.googleapis.com/drive/v3/files", headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, params: { q: `'${this.folderId}' in parents and mimeType='application/vnd.google-apps.document'`, orderBy: "createdTime desc", pageSize: 1, }, }); // Get the latest file ID const latestFileId = fileListResponse.data.files[0].id; // Fetch the content of the latest file const fileContentResponse = await axios($, { method: "GET", url: `https://www.googleapis.com/drive/v3/files/${latestFileId}/export`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, params: { mimeType: "text/plain", }, responseType: "text", }); return { content: fileContentResponse }; }, });
Replace the folderId
prop with the ID of the Google Drive folder where you want to monitor new Google Documents. This component will fetch the content of the latest Google Document in the specified folder. You can adjust the pageSize
parameter to fetch content from more than one file if needed.
error message. TypeError
Cannot read properties of undefined (reading ‘files’)
DETAILS
Detailed/code mode
Google Account
kc@digitaltopical.com
Google Drive Folder ID
1Sd-4LdWthAZrl46-BiMHh59sW5alUG0-
create_post
CONFIGURE
<hrp-shortcut class=“hrp-container” style=“box-sizing: border-box; border-width: 0px; border-style: solid; border-color: transparent; --tw-ring-inset: var(–tw-empty, ); --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(51, 170, 255, .5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; position: fixed; bottom: 24px; right: 24px; z-index: 2147483646; opacity: 1; height: 30px; box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px; border-radius: 4px; background-color: rgb(255, 255, 255); display: flex; flex-direction: row; align-items: center; transition: box-shadow 0.15s ease-in-out 0s;”>
I apologize for the confusion. It seems there was an issue with the code I provided earlier. Let’s try to resolve the error. The error message indicates that the files
property is undefined. This could happen if the API response doesn’t contain any files or if there’s an issue with the API request. Please add a console log statement to print the API response before accessing the files
property, like this: ```
console.log(“File list response:”, fileListResponse.data); const latestFileId = fileListResponse.data.files[0].id;
where should I add?
You should add the console log statement in the component code I provided earlier, right before accessing the files
property. Here’s the updated code with the console log statement added: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, folderId: { type: “string”, label: “Google Drive Folder ID”, }, }, async run({ steps, $ }) { // List files in the specified folder const fileListResponse = await axios($, { method: “GET”, url: “https://www.googleapis.com/drive/v3/files”, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}
, }, params: { q: '${this.folderId}' in parents and mimeType='application/vnd.google-apps.document'
, orderBy: “createdTime desc”, pageSize: 1, }, }); // Log the API response console.log(“File list response:”, fileListResponse.data); // Get the latest file ID const latestFileId = fileListResponse.data.files[0].id; // Fetch the content of the latest file const fileContentResponse = await axios($, { method: “GET”, url: https://www.googleapis.com/drive/v3/files/${latestFileId}/export
, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}
, }, params: { mimeType: “text/plain”, }, responseType: “text”, }); return { content: fileContentResponse }; }, });
, On step 3, I used the following code.
import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
google: {
type: “app”,
app: “google”,
},
folderId: {
type: “string”,
label: “Google Drive Folder ID”,
},
},
async run({ steps, $ }) {
// List files in the specified folder
const fileListResponse = await axios($, {
method: “GET”,
url: “https://www.googleapis.com/drive/v3/files”,
headers: {
Authorization: Bearer ${**this**.google.$auth.oauth_access_token}
,
},
params: {
q: '${**this**.folderId}' in parents and mimeType='application/vnd.google-apps.document'
,
orderBy: “createdTime desc”,
pageSize: 1,
},
});
_// Log the API response_
console.log("File list response:", fileListResponse.data);
_// Get the latest file ID_
**const** latestFileId = fileListResponse.data.files[0].id;
_// Fetch the content of the latest file_
**const** fileContentResponse = **await** axios($, {
method: "GET",
url: `https://www.googleapis.com/drive/v3/files/${latestFileId}/export`,
headers: {
Authorization: `Bearer ${**this**.google.$auth.oauth_access_token}`,
},
params: {
mimeType: "text/plain",
},
responseType: "text",
});
**return** { content: fileContentResponse };
},
});
However, I got an error. TypeError
Cannot read properties of undefined (reading ‘files’)
Previously, I gave my current code. It includes
// Log the API response
console.log(“File list response:”, fileListResponse.data);
_// Get the latest file ID_
**const** latestFileId = fileListResponse.data.files[0].id;
I apologize for the oversight. Since you’ve already logged the API response, let’s analyze the issue further. The error you’re encountering is likely due to either an empty response or a response that doesn’t contain the expected files
property. To handle this case, you can add a conditional check before accessing the files
property. Here’s an updated version of your code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, folderId: { type: "string", label: "Google Drive Folder ID", }, }, async run({ steps, $ }) { const fileListResponse = await axios($, { method: "GET", url: "https://www.googleapis.com/drive/v3/files", headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, params: { q: `'${this.folderId}' in parents and mimeType='application/vnd.google-apps.document'`, orderBy: "createdTime desc", pageSize: 1, }, }); console.log("File list response:", fileListResponse.data); if (fileListResponse.data.files && fileListResponse.data.files.length > 0) { const latestFileId = fileListResponse.data.files[0].id; const fileContentResponse = await axios($, { method: "GET", url: `https://www.googleapis.com/drive/v3/files/${latestFileId}/export`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, params: { mimeType: "text/plain", }, responseType: "text", }); return { content: fileContentResponse }; } else { console.log("No files found in the specified folder."); return { content: "No files found in the specified folder." }; } }, });
This code checks if the files
property exists and if it has at least one element before accessing the id
property. If no files are found, it logs a message and returns a message indicating that no files were found in the specified folder.