// JavaScript example to invite users
const fetch = require('node-fetch');
// Step 1: Authenticate
const authUrl = "https://api.mudstack.com/auth/token";
const authData = {
key: "<your_key>",
secret: "<your_secret>"
};
const authHeaders = { "x-account-id": "<your_account_id>", "Content-Type": "application/json" };
fetch(authUrl, { method: "POST", headers: authHeaders, body: JSON.stringify(authData) })
.then(res => res.json())
.then(authResponse => {
const token = authResponse.token;
// Step 2: Invite users
const url = "https://api.mudstack.com/accounts/invites";
const headers = {
"Authorization": `Bearer ${token}`,
"x-workspace-id": "<workspace_id>",
"x-account-id": "<account_id>",
"Content-Type": "application/json"
};
const data = {
invites: [
{
email: "user1@example.com",
roles: ["Editor"],
workspace_ids: ["workspace1"]
},
{
email: "user2@example.com",
roles: ["Viewer"],
workspace_ids: ["workspace2", "workspace3"]
}
]
};
fetch(url, { method: "POST", headers, body: JSON.stringify(data) })
.then(res => res.json())
.then(console.log);
});