This topic was automatically generated from Slack. You can find the original thread here.
i want OCRspace to extract the text from a picture from a specific URL. The URL will come from a google sheets document. I want the adding of a new URL to the google sheets to trigger my workflow, making the OCRspace api use that URL to extract the text. How do i do that?
To achieve this, you can create a Pipedream workflow with the following steps: 1. Use the Google Sheets - New Row trigger to start the workflow when a new row is added to your Google Sheets document. Make sure to connect your Google Sheets account and select the appropriate document and sheet. 2. Add a Code step to extract the URL from the new row data. Here’s an example: export default defineComponent({ async run({ steps }) { const newRowData = steps.trigger.event.newRowData; const url = newRowData["URL"]; // Replace "URL" with the column name containing the URL in your sheet return { url }; }, }); 3. Add another Code step to make a request to the OCRSpace API using the extracted URL. Here’s an example: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { ocrspace: { type: "app", app: "ocrspace", }, }, async run({ steps, $ }) { const url = steps.previous_step_name.url; // Replace "previous_step_name" with the name of the previous step return await axios($, { url: `https://api.ocr.space/parse/imageurl`, params: { apikey: `${this.ocrspace.$auth.apikey}`, url: url, }, }); }, }); Make sure to replace previous_step_name with the actual name of the previous step that extracts the URL. This workflow will be triggered when a new row is added to your Google Sheets document, extract the URL from the new row, and use OCRSpace to extract text from the image at the specified URL.
i am getting the error in my step number 2 that you outled:
TypeError
Cannot read properties of undefined (reading ‘BZNS_URL’)
DETAILS
at Object.run (file:///tmp/pdg/dist/code/3d6ddf3e410218383a25291a4123cdc94643db74e6a15769744a31d7375d9e88/component.mjs:4:27)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
I apologize for the confusion. It seems there’s an issue with accessing the URL from the newRowData. Let’s modify the step 2 code to handle this correctly: ```
export default defineComponent({ async run({ steps }) { const newRowData = steps.trigger.event.newRowData; const columnName = “BZNS_URL”; // Replace “BZNS_URL” with the correct column name containing the URL in your sheet if (newRowData.hasOwnProperty(columnName)) { const url = newRowData[columnName]; return { url }; } else { throw new Error(Column "${columnName}" not found in newRowData.); } }, });
I apologize for the inconvenience. Let’s try to debug the issue. Please share the error message you’re encountering, and if possible, provide the current code for step 2. This will help me identify the problem and suggest a solution.
i am still getting an error:
Cannot read properties of undefined (reading ‘hasOwnProperty’) DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/c8a92ffa23d1cad23458e82e1f92c34b5e3b84a2ac6678f2af23ae7df53bddd3/component.mjs:6:20)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
I apologize for the confusion. It seems the issue is related to accessing the newRowData. Let’s try a different approach to access the URL from the newRowData in step 2: export default defineComponent({ async run({ steps }) { const newRowData = steps.trigger.event.newRowData; const columnName = "BZNS_URL"; // Replace "BZNS_URL" with the correct column name containing the URL in your sheet if (newRowData && Object.prototype.hasOwnProperty.call(newRowData, columnName)) { const url = newRowData[columnName]; return { url }; } else { throw new Error(`Column "${columnName}" not found in newRowData.`); } }, }); This code uses Object.prototype.hasOwnProperty.call() to check if the columnName exists in newRowData and extracts the URL accordingly. Make sure to replace “BZNS_URL” with the correct column name in your Google Sheet.