I am trying to get the response JSON data from this post request. I have followed tutorial and contacted API provider. Can some please help? The address and zipcode entered by the user from my page code should be sent in the body of my serviceModule code. Currently just trying to console log the response data, but would like to save to a collection eventually. I would appreciate any guidance. Thank you.
BACK END CODE:
// Filename: backend/serviceModule.jsw (web modules need to have a *.jsw* extension)
import { fetch } from 'wix-fetch';
// wix-fetch is the API we provide to make https calls in the backend
const user = 'XXXXXXXXXXXXXXXX';
const pass = 'XXXXXXXXXXXXXXXX';
export function sendOrder(address, zipcode) {
return fetch('https://api.housecanary.com/v2/property/sales_history', {
method: 'post',
headers: {
'Content-Type': 'application/json',
'auth': { 'user': user, 'pass': pass },
},
body: JSON.stringify({ "address": address, "zipcode": zipcode }),
}).then.then(function (response) {
if (response.status >= 200 && response.status < 300)
return response.text();
console.log(response)
});
}
PAGE CODE:
import { sendOrder } from 'backend/serviceModule';
//import wixData from 'wix-data';
//let zip = ($w('#zipcode').value
//let add = ($w('#address').value
export function button1_click(event, $w) {
sendOrder(
$w("#address").value,
$w("#zipcode").value)
.then(function () {
console.log("response");
});
}