I am getting the following error:
TypeError
Cannot read properties of undefined (reading 'createdTime')
I am getting the following error:
TypeError
Cannot read properties of undefined (reading 'createdTime')
I apologize for the confusion. It seems I made a mistake in accessing the createdTime
property from the response. Please update the code as follows: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, fileId: { type: "string", label: "File ID", }, }, async run({ steps, $ }) { const url = `https://www.googleapis.com/drive/v3/files/${this.fileId}?fields=createdTime&supportsAllDrives=true`; const headers = { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }; const response = await axios($, { method: "GET", url, headers, }); const creationDateUTC = new Date(response.data.createdTime); const estDate = new Intl.DateTimeFormat("en-US", { timeZone: "America/New_York", year: "numeric", month: "2-digit", day: "2-digit", }).format(creationDateUTC); const [month, day, year] = estDate.split("/"); const formattedDate = `${year}-${month}-${day}`; return formattedDate; }, });
I’ve updated the code to correctly access the createdTime
property from the response.data
object. This should resolve the error you encountered.
I implemented the new code and I’m still getting this error:
TypeError
Cannot read properties of undefined (reading 'createdTime')
I apologize for the inconvenience. Let’s try to debug the issue. Please add a console.log statement to log the response data before accessing the createdTime
property. Update the code as follows: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, fileId: { type: “string”, label: “File ID”, }, }, async run({ steps, $ }) { const url = https://www.googleapis.com/drive/v3/files/${this.fileId}?fields=createdTime&supportsAllDrives=true
; const headers = { Authorization: Bearer ${this.google.$auth.oauth_access_token}
, }; const response = await axios($, { method: “GET”, url, headers, }); console.log(“Response data:”, response.data); const creationDateUTC = new Date(response.data.createdTime); const estDate = new Intl.DateTimeFormat(“en-US”, { timeZone: “America/New_York”, year: “numeric”, month: “2-digit”, day: “2-digit”, }).format(creationDateUTC); const [month, day, year] = estDate.split(“/”); const formattedDate = ${year}-${month}-${day}
; return formattedDate; }, });
Here is what it said:
Response data: undefined
I apologize for the confusion. It seems the API response is not returning the expected data. To further investigate the issue, let’s log the entire response object instead of just the response.data
. Update the code as follows: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, fileId: { type: “string”, label: “File ID”, }, }, async run({ steps, $ }) { const url = https://www.googleapis.com/drive/v3/files/${this.fileId}?fields=createdTime&supportsAllDrives=true
; const headers = { Authorization: Bearer ${this.google.$auth.oauth_access_token}
, }; const response = await axios($, { method: “GET”, url, headers, }); console.log(“Full response:”, response); if (response.data) { const creationDateUTC = new Date(response.data.createdTime); const estDate = new Intl.DateTimeFormat(“en-US”, { timeZone: “America/New_York”, year: “numeric”, month: “2-digit”, day: “2-digit”, }).format(creationDateUTC); const [month, day, year] = estDate.split(“/”); const formattedDate = ${year}-${month}-${day}
; return formattedDate; } else { console.log(“Error: Response data is undefined.”); throw new Error(“Unable to retrieve createdTime from the API response.”); } }, });
Here is the log:
Full response: { createdTime: '2023-07-31T21:51:49.368Z' }
Error: Response data is undefined.
I apologize for the confusion in my previous response. It seems the response object is not nested under the data
property. Since the createdTime
is directly available in the response object, you can update the code as follows: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, fileId: { type: “string”, label: “File ID”, }, }, async run({ steps, $ }) { const url = https://www.googleapis.com/drive/v3/files/${this.fileId}?fields=createdTime&supportsAllDrives=true
; const headers = { Authorization: Bearer ${this.google.$auth.oauth_access_token}
, }; const response = await axios($, { method: “GET”, url, headers, }); console.log(“Full response:”, response); const creationDateUTC = new Date(response.createdTime); const estDate = new Intl.DateTimeFormat(“en-US”, { timeZone: “America/New_York”, year: “numeric”, month: “2-digit”, day: “2-digit”, }).format(creationDateUTC); const [month, day, year] = estDate.split(“/”); const formattedDate = ${year}-${month}-${day}
; return formattedDate; }, });