Created
April 10, 2024 02:36
-
-
Save tommoor/93523d24f4ccb100c641c55052ac3f94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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