const API_URL = "https://api.pushbase.dev/devices/import";
const API_KEY = "YOUR_API_KEY"; // Available in Pushbase dashboard app setting section
const myHeaders = new Headers();
myHeaders.append("x-api-key", API_KEY);
myHeaders.append("Content-Type", "application/json");
/* Replace this with the subscribed device records from your existing database.
*
*/
const devices = [
{
/* Required properties*/
platform: "ios",
country: "PL",
language: "PL",
timezone: "Europe/Warsaw",
expo_push_token: "ExponentPushToken[VSdTS398767-876hSpj4Aoc9]",
/* Optional properties*/
device_push_token: "c5b8u2adQjqey4fmIP8UYN:APA91bHiAM88JhhaYrLm9h9DKRzOdNAs3LIk6..."
/* Location specific */
region: "Mazowieckie",
city: "Warsaw",
latitude: "52.237049",
longitude: "21.017532",
/* User identity*/
external_id: "cd23bf3c-bddf-431d-9145-d9b41fcecdcd",
external_name: "Maria Curie",
external_email: "marie-curie@kva.se",
external_phone: "08-673 95 00",
/* Device specific*/
manufacturer: "Apple",
brand: "Apple",
model: "iPhone 16",
os_name: "iOS",
os_version: "26.0",
},
{
platform: "android",
country: "US",
language: "EN",
timezone: "America/New_York",
expo_push_token: "ExponentPushToken[TAHZDfF9qqG10FaYku9eB9]",
//... more properties here
},
];
for (const device of devices) {
const raw = JSON.stringify({
device,
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow",
};
fetch(API_URL, requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
}