apolloconfig/apollo · error · BadRequestException

Params(AppId) can not be empty.

Error message

Params(AppId) can not be empty.

What it means

Thrown in assignRoleToConsumer when the NamespaceDTO parsed from the request body has a null or empty appId field. Apollo requires the appId to identify which application the consumer token role should be attached to. This validation runs before any role assignment logic, so an empty appId means the request cannot proceed.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java:390

  @Override
  @PreAuthorize(value = "@unifiedPermissionValidator.isSuperAdmin()")
  public ResponseEntity<Object> getConsumerTokenByAppId(String appId) {
    requirePortalUserRequest();
    return ResponseEntity.ok(consumerService.getConsumerTokenByAppId(appId));
  }

  @Override
  @PreAuthorize(value = "@unifiedPermissionValidator.isSuperAdmin()")
  public ResponseEntity<List<Object>> assignRoleToConsumer(String token, String type, Object body,
      String envs) {
    requirePortalUserRequest();
    NamespaceDTO namespace = convertBody(body, NamespaceDTO.class);
    List<ConsumerRole> consumerRoles = new ArrayList<>(8);
    String appId = namespace.getAppId();
    String namespaceName = namespace.getNamespaceName();

    if (StringUtils.isEmpty(appId)) {
      throw new BadRequestException("Params(AppId) can not be empty.");
    }
    if (Objects.equals("AppRole", type)) {
      return ResponseEntity.ok(asObjects(Collections
          .singletonList(consumerService.assignAppRoleToConsumer(token, appId, currentUserId()))));
    }
    if (StringUtils.isEmpty(namespaceName)) {
      throw new BadRequestException("Params(NamespaceName) can not be empty.");
    }
    if (envs != null) {
      for (String env : envs.split(",")) {
        if (StringUtils.isEmpty(env)) {
          continue;
        }
        parseEnv(env);
        consumerRoles.addAll(consumerService.assignNamespaceRoleToConsumer(token, appId,
            namespaceName, env, currentUserId()));
      }
      return ResponseEntity.ok(asObjects(consumerRoles));

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Include a non-empty appId in the request body JSON, e.g. {"appId":"myApp", "namespaceName":"application"}.
  2. Verify the Content-Type header is application/json so Jackson maps the body to NamespaceDTO correctly.
  3. Check for field-name casing — Apollo's NamespaceDTO uses camelCase appId.

Example fix

// before
POST /consumer/createConsumerRole
{}

// after
POST /consumer/createConsumerRole
{"appId":"myApp","namespaceName":"application"}
Defensive patterns

Strategy: validation

Validate before calling

// Validate body before sending
NamespaceDTO body = new NamespaceDTO();
body.setAppId(appId);
if (StringUtils.isEmpty(body.getAppId())) {
  throw new IllegalArgumentException("appId must not be empty");
}

Type guard

function hasValidAppId(body: unknown): body is { appId: string } {
  return typeof body === 'object' && body !== null
    && typeof (body as any).appId === 'string'
    && (body as any).appId.trim().length > 0;
}

Prevention

When it happens

Trigger: A POST to the consumer role-assignment endpoint (assignRoleToConsumer) with a JSON body whose appId field is missing, null, or an empty string.

Common situations: The caller omitted appId from the JSON payload; field name casing mismatch (e.g. 'app_id' vs 'appId'); or the body was constructed programmatically with an unset field.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/c75727690045b923. Report an issue: GitHub.