If someone could give some guidance a would really appreciate it. I am able to console log json from a fetch request, but I need to insert the data into a collection.
What I have so far:
BACK END CODE:
// Filename: backend/sendEmail.jsw (web modules need to have a *.jsw* extension)
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 user = "xxxx";
//const pass = "xxxx"
const api_key_id = 'xxxxx';
const api_key_secret = xxxxx';
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 xxxxxx
'Content-Type': "application/json",
},
method: 'post',
})
.then((res) => res.json())
.then((data) => console.log(data))
}
FRONT/PAGE CODE:
import { sendOrder } from 'backend/serviceModule';
export function button1_click(event, $w) {
sendOrder(
$w("#address").value,
$w("#zipcode").value)
}
JSON FROM FETCH RESPONSE:
[
{
"property/sales_history":{
"api_code_description": "ok",
"api_code": 0,
"result":[
{
"fips": "12103",
"event_type": "arms_length_sale",
"apn": "24-30-15-02733-000-0240",
"grantee_1": "LEWIS",
"grantee_2": "LEWIS",
"grantor_2": "BREMM",
"record_page": "731",
"grantor_2_forenames": "JANET",
"amount": 265000,
"grantee_1_forenames": "EDDIE L",
"record_date": "2003-09-08",
"grantee_2_forenames": "SUANN E",
"grantor_1": "BREMM",
"record_doc": "03-380217",
"record_book": "13048",
"grantor_1_forenames": "DAVID A"
}
]
},
"address_info":{
"status":{
"requested_item":{"zipcode": "33777", "address": "8121 Norwood Rd"},
"errors":[],
"changes":["State added or changed", "Locality (city, municipality) added or changed"],
"details":["Address fully verified"],
"match": true
},
"city": "Seminole",
"county_fips": "12103",
"geo_precision": "rooftop",
"block_id": "121030250131007",
"zipcode": "33777",
"blockgroup_id": "121030250131",
"address_full": "8121 Norwood Rd Seminole FL 33777",
"state": "FL",
"msa": "45300",
"metrodiv": null,
"unit": null,
"address": "8121 Norwood Rd",
"lat": 27.85092,
"lng": -82.75181,
"slug": "8121-Norwood-Rd-Seminole-FL-33777",
"zipcode_plus4": "3543"
}
}
]