Webhook Events

users.created

This webhook is triggered when a new user is created.

Payload
{
    "type": "users.created",
    "status": "success",
    "data": {
        "userId": "123", // User's identifier
        "email": "test@test.com", // Optional (if user was created with email)
        "phoneNumber": "123456789" // Optional (if user was created with phone number)
    }
}

users.updated

This webhook is triggered when a user’s email or phone number is successfully updated.

Payload
{
    "type": "users.updated",
    "status": "success",
    "data": {
        "actionId": "1234", // Update action identifier
        "userId": "123", // User identifier
        "oldEmail": "test@test.com", // Optional (if user was created with email)
        "newEmail": "test2@test2.com", // Optional (if user was created with email)
        "oldPhoneNumber": "123456789", // Optional (if user was created with phone number)
        "newPhoneNumber": "987654321" // Optional (if user was created with phone number)
    }
}

Handling Webhooks

To handle webhooks, you need to set up an endpoint in your application that can receive HTTP POST requests from Crossmint. Here’s an example of how you might handle a webhook in a Node.js application:

// Example webhook handler
app.post("/webhooks", (req, res) => {
    const event = req.body;

    switch (event.type) {
        case "users.created":
            handleUserCreated(event.data);
            break;
        case "users.updated":
            handleUserUpdated(event.data);
            break;
        default:
            console.log(`Unhandled event type: ${event.type}`);
    }

    res.sendStatus(200);
});