Save API-key credentials
Validate and save API-key credentials your backend collected for a represented user.
/api/v1/users/:userId/connections/:integrationconst response = await fetch("https://api.smallworld.sh/api/v1/users/customer_123/connections/github", {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify({
"credentials": {
"token": "YOUR_USER_GITHUB_TOKEN"
}
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();
Use your server-side apiKey. Replace the example IDs.
Path parameters#
userIdstringrequiredYour application's user ID, URL-encoded. At most 512 characters, with no surrounding whitespace or null bytes. Encode the IDs
.and..as%2Eand%2E%2E: curl sends these as written, but JavaScript'sfetchremoves them even when encoded.integrationstringrequiredAn integration key from GET /integrations, such as github or notion.
Query parameters#
groupIdstringYour application's group ID: which of the user's groups the result is for. Omit it for a user with no group or one group. Required when the user belongs to several groups. URL-encode it.
Request body#
credentialsobjectrequiredString values keyed by the integration's credentialFields names. Each value is at most 4096 characters; provider-specific rules also apply.
Responses#
The user's own account. The provider accepted the credentials; secret credential values are never returned.
{
"integration": "github",
"userId": "customer_123",
"groupId": null,
"source": "personal",
"overridesGroup": false,
"authScheme": "api_key",
"status": "connected",
"accountId": "123456",
"accountName": "octocat",
"workspaceId": null,
"connectedAt": "2026-10-10T12:00:01.000Z",
"updatedAt": "2026-10-10T12:00:01.000Z",
"error": null
}
More about this endpoint
Fetch /integrations to discover the actual credential fields. This endpoint supports api_key, not oauth2 or none.
Smallworld checks credentials with the provider before storing them encrypted. An unknown user is created after successful verification; reconnecting replaces the existing credentials.
The credentials are the user's own and apply in all of their sessions. When the selected group has a connection to the same integration, the user's account replaces it for their calls, and the response shows overridesGroup true. To save credentials for a group, use POST /groups/:groupId/connections/:integration.
groupId follows the rules of a new session in POST /worlds/:worldId/execute. Without it, a user with no groups is read without a group and a user with one group is read for that group. A user in several groups needs groupId. It chooses the group the returned connection is resolved for. When it fails, no credentials are saved.
The hosted connect-session form is available when you want users to enter their keys without your application handling the credential.