I’m sorry to hear that you’re experiencing issues with your code. It seems like the error is related to accessing the content property. To address this issue, let’s add a check to ensure that response.body.content exists before trying to access its properties. Here’s the updated code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, docId: { type: “string”, label: “Google Doc ID”, }, }, async run({ steps, $ }) { const response = await axios($, { url: https://docs.googleapis.com/v1/documents/${this.docId}, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, }, }); if (response.body && response.body.content) { const firstH1 = response.body.content.find( (element) => element.paragraph && element.paragraph.paragraphStyle.namedStyleType === “HEADING_1” ); if (firstH1) { const h1Text = firstH1.paragraph.elements[0].textRun.content.trim(); return h1Text; } else { console.log(“No H1 found in the document”); } } else { console.log(“No content found in the response”); } }, });
I’m sorry you encountered an error. It seems like you’re trying to access a Google document, but the URL in the error message is not formatted correctly. To access a Google document, you’ll need to use the Google Drive API. Here’s an example Pipedream component that retrieves the content of a Google document using the Google Drive API: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, documentId: { type: "string", label: "Google Document ID", }, }, async run({ steps, $ }) { const url = `https://www.googleapis.com/drive/v3/files/${this.documentId}/export`; const responseType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return await axios($, { method: "GET", url: url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, params: { mimeType: responseType, }, responseType: "arraybuffer", }); }, }); Replace documentId with the actual ID of the Google document you want to access. The ID can be found in the document URL: https://docs.google.com/document/d/<DOCUMENT_ID>/edit. Please let me know if you need further assistance or if you have any questions.
It seems like there’s an issue with the URL you’re using to access the Google Doc. The URL should only contain the document ID, not the entire document URL. You can modify your code to extract the document ID and use it in the API request. Here’s an example of how you can do that: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, docUrl: { type: “string”, label: “Google Doc URL”, }, }, async run({ steps, $ }) { // Extract the document ID from the URL const docId = this.docUrl.match(//d/(.*?)//)[1]; // Make the API request using the extracted document ID try { const response = await axios($, { url: https://docs.googleapis.com/v1/documents/${docId}, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, }, }); return response; } catch (error) { console.error(“Error:”, error); return error; } }, });
It looks like you have two separate components: one for extracting the Google Doc ID from the URL, and another for parsing the ID and fetching the document content. To make this work, you can create a single component that combines both functionalities. Here’s a modified version of your code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, docUrl: { type: “string”, label: “Google Doc URL”, }, }, async run({ steps, $ }) { // Extract the document ID from the URL const regex = /document/d/([a-zA-Z0-9-_]+)/; const match = this.docUrl.match(regex); const docId = match ? match[1] : null; if (!docId) { console.error(“Invalid Google Doc URL”); return; } // Fetch the document content using the extracted document ID try { const response = await axios($, { url: https://docs.googleapis.com/v1/documents/${docId}, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, }, }); if (response.body && response.body.content) { const firstH1 = response.body.content.find( (element) => element.paragraph && element.paragraph.paragraphStyle.namedStyleType === “HEADING_1” ); if (firstH1) { const h1Text = firstH1.paragraph.elements[0].textRun.content.trim(); return h1Text; } else { console.log(“No H1 found in the document”); } } else { console.log(“No content found in the response”); } } catch (error) { console.error(“Error:”, error.message); console.error( “Error details:”, error.response ? error.response.data : “No additional details available” ); } }, });