RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-payload

error-invalid-payload

Error message

Token is required.

What it means

Thrown by 'cloud:connectWorkspace' when the token argument is an empty string. The preceding check(token, String) only enforces the type, so '' passes validation; the explicit `if (!token)` guard then rejects it with error-invalid-payload. A missing or non-string argument fails earlier inside check() with a Match.Error, so this specific error means the token was present but empty.

Source

Thrown at apps/meteor/server/meteor-methods/platform/cloud.ts:133

		methodDeprecationLogger.method('cloud:connectWorkspace', '9.0.0', '/v1/cloud.connectWorkspace');
		check(token, String);

		const uid = Meteor.userId();

		if (!uid) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', {
				method: 'cloud:connectWorkspace',
			});
		}

		if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
			throw new Meteor.Error('error-not-authorized', 'Not authorized', {
				method: 'cloud:connectWorkspace',
			});
		}

		if (!token) {
			throw new Meteor.Error('error-invalid-payload', 'Token is required.', {
				method: 'cloud:connectWorkspace',
			});
		}

		return connectWorkspace(token);
	},
	// Currently unused but will link local account to Rocket.Chat Cloud account.
	async 'cloud:getOAuthAuthorizationUrl'() {
		const uid = Meteor.userId();
		if (!uid) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', {
				method: 'cloud:getOAuthAuthorizationUrl',
			});
		}

		if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
			throw new Meteor.Error('error-not-authorized', 'Not authorized', {
				method: 'cloud:getOAuthAuthorizationUrl',

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Generate the workspace token in the Rocket.Chat Cloud console and paste the full non-empty value
  2. Validate token.trim().length > 0 in the caller before invoking the method
  3. Verify the setting or env var that supplies the token is set at read time
  4. On error, keep the form open and prompt for the token instead of retrying with ''

Example fix

// before
await Meteor.callAsync('cloud:connectWorkspace', token); // token === ''

// after
if (typeof token !== 'string' || token.trim().length === 0) {
  throw new Error('Cloud registration token is required');
}
await Meteor.callAsync('cloud:connectWorkspace', token);
Defensive patterns

Strategy: validation

Validate before calling

const connectWorkspace = async (token: string): Promise<void> => {
  if (typeof token !== 'string' || token.trim().length === 0) {
    throw new Error('Cloud registration token is required');
  }
  await Meteor.callAsync('cloud:connectWorkspace', token);
};

Type guard

import { Meteor } from 'meteor/meteor';

const isMeteorError = (err: unknown, code?: string): err is Meteor.Error =>
  err instanceof Meteor.Error && (code === undefined || err.error === code);

Try / catch

try {
  await Meteor.callAsync('cloud:connectWorkspace', token);
} catch (err) {
  if (isMeteorError(err, 'error-invalid-payload')) {
    // token was empty: keep the form open and prompt for it
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Submitting the Cloud connect form with an empty token field; passing a variable that defaulted to '' (unset env var or empty setting); a copy/paste mistake that yields an empty string.

Common situations: Registration flow started before a token was generated on cloud.rocket.chat; automation reading the token from an unset environment variable; a UI bug sending the form before token state is bound to the input.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/841d8ad2b52855ae. Report an issue: GitHub.