Hello all, I believe this is a general Javascript question. I haven’t run into this before, and I’d like some advice on the best way to solve this.
What I’m Doing
I have airtable data of the shape:
{
"records": [
{
"id": "airtable_record_id",
"fields": {
"Email": "test@email.com",
"Name": "Stetson Test 1"
},
"createdTime": "2021-07-03T17:01:29.000Z"
},
{
"id": "airtable_record_id",
"fields": {
"Email": "test2@email.com",
"Name": "Stetson Test 2"
},
"createdTime": "2021-07-03T17:01:29.000Z"
},
{
"id": "airtable_record_id",
"fields": {
"Email": "test3@email.com",
"Name": "Stetson Test 3"
},
"createdTime": "2021-07-03T17:01:29.000Z"
}
]
}
And I have quickbooks data of the shape:
"Customer": [
{
"Id": "1345135123",
"GivenName": "Stetson",
"FamilyName": "Test 1",
"FullyQualifiedName": "Stetson Test 1",
"DisplayName": "Stetson Test 1",
"PrimaryEmailAddr": {
"Address": "test@email.com"
}
},
{
"Id": "0987098600",
"GivenName": "Stetson",
"FamilyName": "Test 2",
"FullyQualifiedName": "Stetson Test 2",
"DisplayName": "Stetson Test 2",
"PrimaryEmailAddr": {
"Address": "test@email.com"
}
},
{
"Id": "2394798706",
"GivenName": "Stetson",
"FamilyName": "Test 3",
"FullyQualifiedName": "Stetson Test 3",
"DisplayName": "Stetson Test 3",
"PrimaryEmailAddr": {
"Address": "test@email.com"
}
},
-----Desired Outcome----
I want to add the Customer[0].Id
from the quickbooks data to the corresponding airtable data (email address should be the best way to correlate the two). Then the airtable object would look like:
"records": [
{
"id": "airtable_record_id",
"fields": {
"Email": "test@email.com",
"Name": "Stetson Test 1"
"Quickbooks ID": "1345135123"
},
"createdTime": "2021-07-03T17:01:29.000Z"
},...........
How I’m thinking about doing this:
- Loop over airtable data, get email address for each record
- Send API call to quickbooks to get customer using email address
- grab ID from response object
- add quickbooks ID to airtable
- update airtable data via airtable API
This will probably work, but I make a quickbooks and airtable API call each round.
Could I:
- make one API request and get an object of all airtable records
- make one API request and get all quickbooks customers
- run some sort of compare-find-mutate operation on the two arrays of objects to accomplish the same thing?
- once I’ve mutated my airtable data, post update to my airtable base
Is the first way fine and the second way unnecessary?
I get stuck on #3. Not sure how to add the quickbooks ID to my airtable objects once I have both the records array of objects
from airtable and the Customers array of objects
from quickbooks.
I’m working with about 550 records.
Thanks for the advice if you have some!