Storing the JSON value into the Collection

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;
} );

});

There are previous forum posts that can help you with this and note on them that they mention that the IP might not be constant and can change.
https://www.wix.com/corvid/forum/community-discussion/trying-to-pull-users-ip-and-add-it-to-text-field
https://www.wix.com/corvid/forum/community-discussion/users-ip-address
https://www.wix.com/corvid/forum/community-discussion/user-ip-address-finally-resolved

Hi @GOS, have tried some of these and this was the closest one i could get into, but the issue i am facing now, how to save the ip into the DB which we create. Here is the code which i am using to caputre the IP :
import {

fetch 

}

from ‘wix-fetch’;

$w.onReady(function () {

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; 

	}); 

});

Here I can see the IP in the console or Site Logs, but how we store these IP to the DB ? Can you help me out?

Yes, IP wont be constant due to different ISP’s but i would like to store all the IP’s coming to the website.

@givemeawhisky can you please help me out ?