Sending your first event
Run this code in your node.js backend.
import Operational from "@operational.co/sdk";
// Or use this if imports are not supported in your node.js version
// const Operational = require("@operational.co/sdk");
const ops = new Operational("yourapikey");
const e = {
name: "Operational!",
}
await ops.events.ingest(e);
Copyconst bearerToken = 'Bearer apikey';
const baseUrl = 'https://api.operational.co';
const url = `api/${this.version}/log`;
const event = {
name: "test event"
};
fetch(`${baseUrl}/${url}`, {
method: 'POST',
headers: {
'Authorization': bearerToken,
'Content-Type': 'application/json'
},
body: JSON.stringify(event)
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Success:', data);
})
.catch(error => {
console.error('Error:', error);
});
CopyThis will show an event inside ops.
~
12:00 am • Operational!