Javascript
Prerequisites
- ezePing API Key, available instantly after creating an account. You can copy it from here (opens in a new tab).
- Event Category Name is the category to which you want to send this event. If you haven't created an event category yet, you can create a new category here (opens in a new tab).
Payload
You can send any payload, as long as it is in a valid JSON format.
json
'fields': {
'amount': 50,
'plan': 'PRO',
'email': 'user@email.com'
}
Installation
Javascript
const url = 'https://www.ezeping.com/api/v1/events';
const apiKey = '<YOUR_API_KEY>';
const data = {
category: '<YOUR_CATEGORY_NAME>',
fields: {
field1: 'value1', // for example: user id
field2: 'value2' // for example: user email
}
};
async function sendEvent() {
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (response.ok) {
const responseData = await response.json();
console.log("Request was successful:", responseData);
} else {
console.error("Request failed with status:", response.status, await response.text());
}
} catch (error) {
console.error("An error occurred:", error);
}
}
sendEvent();