Hi, I am new to wix, and working on storing the user IP address in the collection, I am fetching the IP address from 3rd party API and can see the data in the console, Next, I want to store the IP address in the database, it’s not happening, can anyone help? Here is the code below :
import wixData from ‘wix-data’;
// …
let countryId = “id-of-usa-item”;
$w.onReady(function () {
//TODO: write your page related code here…
fetch(‘https://extreme-ip-lookup.com/json’, {
method: 'get'
})
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
}
})
.then((json) => {
const ipaddress = json.query;
console.log(ipaddress);
return ipaddress;
});
let toInsert = {
“ipaddress”:“”
};
wixData.insert(“myCollection”, toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
});