Thanks Majd. I am having a bit of a problem understanding as you can see below.
import { fetch } from ‘wix-fetch’;
import wixData from ‘wix-data’;
// wix-fetch is the API we provide to make https calls in the backend
const api_key_id = ‘XXXXXXXX’;
const api_key_secret = ‘XXXXXXXX’;
export function sendOrder(address, zipcode, file) {
return fetch(’ https://api.housecanary.com/v2/property/sales_history ', {
body: JSON.stringify([{ “address”: address, “zipcode”: zipcode }]),
headers: {
Authorization: “Basic XXXXXXXXX”,
‘Content-Type’: “application/json”,
},
method: ‘post’,
})
.then((result) => result.json())
//.then((result) => console.log(result))
.then((data) => {
console.log(data)
const resultArray = […data[0][‘property/sales_history’].result];
resultArray.forEach((item) => {
toInsert[item] = item;
});
let toInsert = {
‘fips’: fips,
‘event’: event,
‘apn’: apn,
‘grantee1’: grantee1,
‘grantee2’: grantee2,
‘grantor2’: grantor2,
‘page’: page,
‘grantor2Fore’: grantor2fore,
‘amount’: amount,
‘grantee1Fore’: grantee1fore,
‘date’: date,
‘grantee2Fore’: grantee2fore,
‘grantor1’: grantor1,
‘doc’: doc,
‘book’: book,
‘grantor1Fore’: grantor1fore
wixData.insert(“SalesHistory”, toInsert)
.then((results) => {
console.log(results); //see if it inserted
})
. catch ((err) => {
console.log(err); //see if error occured
});
});
}