This is very possible.
Here is a snippet from one of my destination functions that performs this action.
call.userId = user;
call.anonymousId = anonymous;
// Learn more at https://segment.com/docs/connections/spec/track/
const endpoint = 'https://api.segment.io/v1/identify'; // replace with your endpoint
let response;
console.log(call);
try {
response = await fetch(endpoint, {
method: 'POST',
headers: {
Authorization: `Basic ${btoa(settings.writeKey + ':')}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(call)
});
} catch (error) {
// Retry on connection error
throw new RetryError(error.message);
}
if (response.status >= 500 || response.status === 429) {
// Retry on 5xx (server errors) and 429s (rate limits)
throw new RetryError(`Failed with ${response.status}`);
}