Skip to content

Instantly share code, notes, and snippets.

@tommoor
Created April 10, 2024 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommoor/93523d24f4ccb100c641c55052ac3f94 to your computer and use it in GitHub Desktop.
Save tommoor/93523d24f4ccb100c641c55052ac3f94 to your computer and use it in GitHub Desktop.
const HOSTNAME = "<OUTLINE SERVER>";
const API_TOKEN = "<API TOKEN>";
// Authenticate
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${API_TOKEN}`,
};
// Create a user
const inviteResponse = await fetch(`https://${HOSTNAME}/api/users.invite`, {
method: "POST",
headers,
body: JSON.stringify({
invites: [
{ email: "user@example.com", name: "Full name", role: "member" }
]
}),
});
const parsed = await inviteResponse.json();
const userId = parsed.data.users[0].id;
// Create a group
const groupResponse = await fetch(`https://${HOSTNAME}/api/groups.create`, {
method: "POST",
headers,
body: JSON.stringify({
name: "All users",
}),
});
const parsed = await groupResponse.json();
const groupId = parsed.data.id;
// Add user to group
const addResponse = await fetch(`https://${HOSTNAME}/api/groups.add_user`, {
method: "POST",
headers,
body: JSON.stringify({
id: groupId,
userId,
}),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment