user-1
(User 1)
August 4, 2023, 5:40pm
1
This topic was automatically generated from Slack. You can find the original thread here .
I have this code but I get an error, can you fix it?
The error says **Cannot read properties of undefined (reading ‘bases’)**
Here’s my code:
import { axios } from “@pipedream /platform”;
export default defineComponent({
props: {
airtable: {
type: “app”,
app: “airtable”,
},
baseId: {
type: “string”,
label: “Base”,
async options(opts) {
const url = “https://api.airtable.com/v0/meta/bases” ;
const headers = {
Authorization: Bearer ${**this**.airtable.$auth.api_key}
,
};
const { data } = await axios(this , { url, headers });
return data.bases.map((base) => ({ label: base.name, value: base.id }));
},
},
tableId: {
type: “string”,
label: “Table”,
async options({ baseId }) {
const url = https://api.airtable.com/v0/${baseId}/tables
;
const headers = {
Authorization: Bearer ${**this**.airtable.$auth.api_key}
,
};
const { data } = await axios(this , { url, headers });
return data.tables.map((table) => ({ label: table.name, value: table.id }));
},
},
email: {
type: “string”,
label: “Email”,
description: “Email to search for”,
},
},
async run({ steps, $ }) {
const twoDaysAgo = new Date();
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
const url = https://api.airtable.com/v0/${**this**.baseId}/${**this**.tableId}?filterByFormula=AND({Email}=‘${**this**.email}‘, IS_AFTER({Created Time}, ‘${twoDaysAgo.toISOString()}’))
;
const headers = {
Authorization: Bearer ${**this**.airtable.$auth.api_key}
,
“Content-Type”: “application/json”,
};
const response = await axios($, { url, headers });
return response.data.records;
},
});
user-1
(User 1)
August 4, 2023, 5:40pm
2
I noticed an issue in your code related to the string quotes. You’re using curly quotes (“ ”) instead of straight quotes (" "). Please replace all curly quotes with straight quotes and try running the code again. Here’s the corrected code: ```
import { axios } from “@pipedream /platform”; export default defineComponent({ props: { airtable: { type: “app”, app: “airtable”, }, baseId: { type: “string”, label: “Base”, async options(opts) { const url = “https://api.airtable.com/v0/meta/bases ”; const headers = { Authorization: Bearer ${this.airtable.$auth.api_key}
, }; const { data } = await axios(this, { url, headers }); return data.bases.map((base) => ({ label: base.name, value: base.id })); }, }, tableId: { type: “string”, label: “Table”, async options({ baseId }) { const url = https://api.airtable.com/v0/${baseId}/tables
; const headers = { Authorization: Bearer ${this.airtable.$auth.api_key}
, }; const { data } = await axios(this, { url, headers }); return data.tables.map((table) => ({ label: table.name, value: table.id })); }, }, email: { type: “string”, label: “Email”, description: “Email to search for”, }, }, async run({ steps, $ }) { const twoDaysAgo = new Date(); twoDaysAgo.setDate(twoDaysAgo.getDate() - 2); const url = https://api.airtable.com/v0/${this.baseId}/${this.tableId}?filterByFormula=AND({Email}='${this.email}', IS_AFTER({Created Time}, '${twoDaysAgo.toISOString()}'))
; const headers = { Authorization: Bearer ${this.airtable.$auth.api_key}
, “Content-Type”: “application/json”, }; const response = await axios($, { url, headers }); return response.data.records; }, });
user-1
(User 1)
August 4, 2023, 5:40pm
4
I apologize for the confusion earlier. To better assist you, can you please provide more information about the issue you’re facing? Are you encountering any error messages or unexpected behavior in your Pipedream workflow? The more details you can provide, the better I can help you resolve the issue.
user-1
(User 1)
August 4, 2023, 5:40pm
5
What I’m trying to do is pulling all the bases and tables in the props dropdown and search for a specific email in the that was created in less than 2 days, I have a field called created time
user-1
(User 1)
August 4, 2023, 5:40pm
6
I understand that you want to pull all bases and tables in the props dropdown and search for a specific email created in less than 2 days with a field called created time
. Here’s an updated version of the code that should help you achieve this: ```
import { axios } from “@pipedream /platform”; export default defineComponent({ props: { airtable: { type: “app”, app: “airtable”, }, baseId: { type: “string”, label: “Base”, async options(opts) { const url = “https://api.airtable.com/v0/meta/bases ”; const headers = { Authorization: Bearer ${this.airtable.$auth.api_key}
, }; const { data } = await axios(this, { url, headers }); return data.bases.map((base) => ({ label: base.name, value: base.id })); }, }, tableId: { type: “string”, label: “Table”, async options({ baseId }) { const url = https://api.airtable.com/v0/${baseId}/tables
; const headers = { Authorization: Bearer ${this.airtable.$auth.api_key}
, }; const { data } = await axios(this, { url, headers }); return data.tables.map((table) => ({ label: table.name, value: table.id })); }, }, email: { type: “string”, label: “Email”, description: “Email to search for”, }, }, async run({ $ }) { const twoDaysAgo = new Date(); twoDaysAgo.setDate(twoDaysAgo.getDate() - 2); const url = https://api.airtable.com/v0/${this.baseId}/${encodeURIComponent(this.tableId)}?filterByFormula=AND({Email}='${this.email}', IS_AFTER({Created Time}, '${twoDaysAgo.toISOString()}'))
; const headers = { Authorization: Bearer ${this.airtable.$auth.api_key}
, “Content-Type”: “application/json”, }; const response = await axios(this, { url, headers }); return response.data.records; }, });