Skip to main content

How to clean up unused licenses automatically

Licenses cost money every month, and in larger teams some of them end up with people who left or stopped using Sally. This guide shows how to find those members through the API, take their license away and then reduce the subscription so that you only pay for what is assigned. At the end there is a complete script you can run on a schedule.

You need a token of an owner or admin of the company account, because only they may read the usage and change licenses, exactly as in Sally. Every example works as it stands once SALLY_TOKEN and DIRECTORY_ID are set, see the Quickstart.

Quick navigation

  1. Find members who don't use their license
  2. Take a license away
  3. Check the license statistics
  4. Reduce the subscription
  5. Complete clean-up script
  6. Endpoints at a glance
Not for reseller-managed accounts

If a reseller partner manages your company account, the partner books the licenses. The subscription endpoints then answer 409 MANAGED_BY_RESELLER_PARTNER. Taking licenses away from members still works.

1. Find members who don't use their license​

GET/v1.0/directories/{directoryId}/memberships/usage returns the same numbers as the Usage tab of the user management in Sally: per member the last sign-in, the transcribed meetings and uploads and the minutes, for the period you choose. It takes these query parameters:

ParameterTypeDefaultDescription
periodstringlast30last7, last30, last90, last365 or all.
pageinteger1Page number, starting at 1.
pageSizeinteger25Entries per page, at most 100.
fieldsstringComma-separated list of the fields to return, see Field selection.

This request loads the usage of the last 90 days:

curl "https://api.sally.io/v1.0/directories/$DIRECTORY_ID/memberships/usage?period=last90&pageSize=100" \
-H "Authorization: Bearer $SALLY_TOKEN"
200 OK
{
"page": 1,
"pageSize": 100,
"total": 2,
"hasMore": false,
"period": "last90",
"items": [
{
"userId": "11f967df-7dd1-4719-a9aa-46530940c443",
"roleId": "164531fc-9be4-4de4-a183-89cc85d6a98c",
"licenseId": "f5f084e9-b993-425f-ad36-bfd5dc3f0e65",
"isBlocked": false,
"lastLoginOn": "2026-11-20T08:12:40Z",
"transcribedMeetingsCount": 23,
"transcribedUploadedRecordingsCount": 2,
"transcribedMinutes": 1240,
"usedQuotaMinutes": 610
},
{
"userId": "8a0c2f7e-3b51-4d2a-9c6e-7f14b2d0e935",
"roleId": "164531fc-9be4-4de4-a183-89cc85d6a98c",
"licenseId": "f5f084e9-b993-425f-ad36-bfd5dc3f0e65",
"isBlocked": false,
"lastLoginOn": "2026-07-03T14:55:02Z",
"transcribedMeetingsCount": 0,
"transcribedUploadedRecordingsCount": 0,
"transcribedMinutes": 0,
"usedQuotaMinutes": 0
}
]
}
FieldTypeDescription
userIdstringId of the member.
roleIdstringRole in the company account, resolve it via GET /v1.0/roles.
licenseIdstring | nullLicense of the member, resolve it via GET /v1.0/licenses.
isBlockedbooleanWhether the member is blocked.
lastLoginOnstring | nullLast sign-in to Sally (ISO-8601, UTC), null if the member never signed in.
transcribedMeetingsCountnumberRecorded meetings with a transcript in the period that the member took part in.
transcribedUploadedRecordingsCountnumberUploaded recordings with a transcript in the period.
transcribedMinutesnumberMinutes of those recordings. A recording counts for every participant, so don't add this up across members.
usedQuotaMinutesnumberTranscription quota used in the period. Every recording counts once, so this one can be added up.

Which member counts as inactive is your decision. A rule that works well: no sign-in for 60 days, or never, and no transcribed meeting or upload in the last 90 days. The member list also carries lastLoginOn, see GET/v1.0/directories/{directoryId}/memberships/users, so you can show names next to the ids.

2. Take a license away​

PATCH/v1.0/directories/{directoryId}/memberships/{userId} changes the license, role or block of a member, with the same rules as the user management in Sally. To take a license away, set the license None. The member stays in the company account and keeps their data, they just can't record any more. Look up the id of None once with GET/v1.0/licenses.

FieldTypeDescription
licenseIdstringNew license. The license None takes the license away.
roleIdstringNew role. Only owners may change roles.
isBlockedbooleanBlock or unblock the member.

Send only the fields you want to change:

curl -X PATCH "https://api.sally.io/v1.0/directories/$DIRECTORY_ID/memberships/$USER_ID" \
-H "Authorization: Bearer $SALLY_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"licenseId\": \"$NONE_LICENSE_ID\"}"
200 OK
{
"directoryId": "5daeda15-8fc7-4693-a1e1-13119cceb461",
"userId": "8a0c2f7e-3b51-4d2a-9c6e-7f14b2d0e935",
"roleId": "164531fc-9be4-4de4-a183-89cc85d6a98c",
"licenseId": "0d3e7a91-5c24-4b8f-a6e2-9f1b4c7d2e58",
"isBlocked": false
}

The change appears in the audit log like a change in Sally, marked as made through the Public API. These answers mean something specific:

StatuscodeWhat to do
400There is no free license in the tier you assign. Only relevant when you give a license, not when you take one away.
403ADMIN_ONLY_MEMBERSThe token belongs to neither an owner nor an admin.
403MEMBER_IS_SCIM_MANAGEDThe member is managed through SCIM. Change the license in your identity provider.
403OWNER_PROTECTEDThe change would affect an owner. Skip this member.
404USER_NOT_MEMBERThe user is not a member of this company account.

3. Check the license statistics​

A license you take away is free, but you keep paying for it until you reduce the subscription. GET/v1.0/directories/{directoryId}/license-statistics shows per tier how many licenses are available, assigned and free, computed exactly like the Billing page in Sally:

curl "https://api.sally.io/v1.0/directories/$DIRECTORY_ID/license-statistics" \
-H "Authorization: Bearer $SALLY_TOKEN"
200 OK
{
"hasIndividualContract": false,
"starter": {
"individualContract": {"totalCount": 0, "assignedCount": 0, "freeCount": 0},
"subscription": {"totalCount": 25, "assignedCount": 21, "freeCount": 4}
},
"pro": {
"individualContract": {"totalCount": 0, "assignedCount": 0, "freeCount": 0},
"subscription": {"totalCount": 3, "assignedCount": 3, "freeCount": 0}
},
"enterprise": {
"individualContract": {"totalCount": 0, "assignedCount": 0, "freeCount": 0},
"subscription": {"totalCount": 0, "assignedCount": 0, "freeCount": 0}
}
}

Every tier is split into two sources. individualContract holds licenses from an individual contract with Sally, subscription those from the online subscription. Assigned licenses fill the individual contract first, so subscription.assignedCount is exactly the lowest number you can reduce the subscription to. In the example, four Starter licenses are free and can go.

4. Reduce the subscription​

First load the subscriptions with GET/v1.0/directories/{directoryId}/subscriptions to get the subscriptionId of the running one:

curl "https://api.sally.io/v1.0/directories/$DIRECTORY_ID/subscriptions" \
-H "Authorization: Bearer $SALLY_TOKEN"

Then send the new target per tier to PATCH/v1.0/directories/{directoryId}/subscriptions/{subscriptionId}. Send only the tiers that change. A reduction needs no acceptTerms, that is only required for an increase:

curl -X PATCH "https://api.sally.io/v1.0/directories/$DIRECTORY_ID/subscriptions/$SUBSCRIPTION_ID" \
-H "Authorization: Bearer $SALLY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"starterLicensesCount": 21}'
200 OK
{
"subscriptionId": "77e63339-474b-468f-a6b0-99e59513cd75",
"billingInterval": "monthly",
"status": "active",
"starterLicensesCount": 25,
"proLicensesCount": 3,
"enterpriseLicensesCount": 0,
"currentPeriodEnd": "2026-12-14T09:30:00Z",
"trialEndsOn": null,
"isCanceled": false,
"scheduledChange": {
"starterLicensesCount": 21,
"proLicensesCount": 3,
"enterpriseLicensesCount": 0,
"effectiveOn": "2026-12-14T09:30:00Z"
}
}

A reduction works like in Sally:

  • It takes effect at the end of the current period, without a credit. Until then the old number stays, and the new one shows up in scheduledChange. During a trial it applies at once.
  • Never below the assigned licenses. A target below subscription.assignedCount answers 409 BELOW_ASSIGNED_LICENSES with the tier and the minimum. Take the licenses away from members first, as in step 2.
  • A new target replaces the scheduled one. Sending the current number or a higher one removes the scheduled reduction.

Increasing works the same way with acceptTerms: true and is charged right away. All rules, including tier switches and bank confirmation, are listed on PATCH/v1.0/directories/{directoryId}/subscriptions/{subscriptionId}.

5. Complete clean-up script​

The script combines the four steps. It finds members without a sign-in for INACTIVE_DAYS days and without any transcribed meeting or upload in the last 90 days, takes their license away and reduces the running subscription to the licenses still assigned. It only reads by default and prints what it would do. Set DRY_RUN=false once the list looks right.

clean-up-licenses.mjs
// Node 18 or newer: node clean-up-licenses.mjs
const BASE = `https://api.sally.io/v1.0/directories/${process.env.DIRECTORY_ID}`;
const INACTIVE_DAYS = Number(process.env.INACTIVE_DAYS ?? 60);
const DRY_RUN = process.env.DRY_RUN !== 'false';
const headers = {Authorization: `Bearer ${process.env.SALLY_TOKEN}`, 'Content-Type': 'application/json'};

async function call(method, url, body) {
const response = await fetch(url, {method, headers, body: body && JSON.stringify(body)});
const data = response.status === 204 ? null : await response.json();
if (!response.ok) {
const error = new Error(`${method} ${url}: ${response.status} ${data?.code ?? ''} ${data?.message ?? ''}`);
error.code = data?.code;
throw error;
}
return data;
}

// 1. Id of the license "None", which takes a license away
const licenses = await call('GET', 'https://api.sally.io/v1.0/licenses');
const none = licenses.find((license) => license.name.toLowerCase() === 'none');
if (!none) throw new Error('License "None" not found');

// 2. Usage of all members, page by page
const members = [];
for (let page = 1; ; page++) {
const result = await call('GET', `${BASE}/memberships/usage?period=last90&pageSize=100&page=${page}`);
members.push(...result.items);
if (!result.hasMore) break;
}

// 3. Inactive: a license, no sign-in for INACTIVE_DAYS days and nothing transcribed in 90 days
const cutoff = Date.now() - INACTIVE_DAYS * 24 * 60 * 60 * 1000;
const inactive = members.filter(
(m) =>
m.licenseId &&
m.licenseId !== none.licenseId &&
(!m.lastLoginOn || Date.parse(m.lastLoginOn) < cutoff) &&
m.transcribedMeetingsCount + m.transcribedUploadedRecordingsCount === 0,
);
console.log(`${inactive.length} of ${members.length} members are inactive.`);

// 4. Take the licenses away
for (const member of inactive) {
console.log(`${DRY_RUN ? '[dry run] ' : ''}Taking the license away from ${member.userId} (last sign-in ${member.lastLoginOn ?? 'never'})`);
if (DRY_RUN) continue;
try {
await call('PATCH', `${BASE}/memberships/${member.userId}`, {licenseId: none.licenseId});
} catch (error) {
if (['MEMBER_IS_SCIM_MANAGED', 'OWNER_PROTECTED'].includes(error.code)) console.log(` skipped: ${error.code}`);
else throw error;
}
}

// 5. Reduce the running subscription to the licenses still assigned
const statistics = await call('GET', `${BASE}/license-statistics`);
const {items: subscriptions} = await call('GET', `${BASE}/subscriptions`);
const running = subscriptions.find((s) => s.status === 'active' || s.status === 'trialing');
if (!running) {
console.log('No running subscription, nothing to reduce.');
} else {
const change = {};
for (const tier of ['starter', 'pro', 'enterprise']) {
const target = statistics[tier].subscription.assignedCount;
if (target < running[`${tier}LicensesCount`]) change[`${tier}LicensesCount`] = target;
}
if (Object.keys(change).length === 0) {
console.log('The subscription already matches the assigned licenses.');
} else if (DRY_RUN) {
console.log('[dry run] Would reduce the subscription to', change);
} else {
const updated = await call('PATCH', `${BASE}/subscriptions/${running.subscriptionId}`, change);
console.log('Reduction scheduled:', updated.scheduledChange);
}
}
Recommendation

Run the script with DRY_RUN left on first and check the list with the people responsible. Members who are on parental leave or only record a few times a year look inactive too. Once the list fits, schedule it once a month, a few days before the end of the billing period.

6. Endpoints at a glance​