apolloconfig/apollo · error · BadRequestException

AppId not equal. AppId in path =

Error message

AppId not equal. AppId in path = %s, AppId in payload = %s

What it means

HTTP 400 (BadRequestException). Thrown by NamespaceController.validateCreateAppNamespaceRequest when the appId in the URL path does not equal the appId field in the OpenAppNamespaceDTO request body. Apollo treats the path as authoritative; the body must agree. This guards against clients that template the path and body from different sources.

Solutions

  1. Set appNamespace.setAppId(appId) to the same value used in the path before sending.
  2. Validate the two values match client-side before the request (assertObjects.equals(pathAppId, dto.getAppId())).
  3. If creating app namespaces for several apps, build a fresh DTO per app rather than mutating one shared instance.
  4. Check the OpenAPI spec/model field name if integrating generated code (appId vs appId property).

Example fix

// before
String pathAppId = "appA";
OpenAppNamespaceDTO dto = templateFromAppB; // dto.appId = appB
client.createAppNamespace(pathAppId, dto); // 400 AppId not equal

// after
dto.setAppId(pathAppId);
client.createAppNamespace(pathAppId, dto);
Defensive patterns

Strategy: validation

Validate before calling

// Validate path appId == body appId before the request.
if (!Objects.equals(pathAppId, dto.getAppId())) {
  dto.setAppId(pathAppId); // fix, or fail fast client-side
}
assert Objects.equals(pathAppId, dto.getAppId());

Type guard

null

Try / catch

try {
  client.createAppNamespace(pathAppId, dto);
} catch (HttpClientErrorException.BadRequest e) {
  if (e.getResponseBodyAsString().contains("AppId not equal")) {
    dto.setAppId(pathAppId); client.createAppNamespace(pathAppId, dto);
  }
}

Prevention

When it happens

Trigger: POST /openapi/v1/apps/{appId}/appnamespaces where {appId} in the path differs from appNamespace.appId in the JSON body — e.g. copying a body template from app A while posting to app B's path, or a client that fills the body appId from a stale variable.

Common situations: Looping over multiple apps and reusing a DTO whose appId was set once; copy-pasted request body not updated after changing the path; SDK bug where path and body appIds diverge; refactor that renamed the appId field setter.

Related errors


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

Appendix: source

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

        .ok(namespaceOpenApiService.findMissingNamespaces(appId, env, clusterName));
  }

  @PreAuthorize(value = "@unifiedPermissionValidator.hasCreateNamespacePermission(#appId)")
  @ApolloAuditLog(type = OpType.CREATE, name = "Namespace.createMissingNamespaces")
  @Override
  public ResponseEntity<Void> createMissingNamespaces(String appId, String env, String clusterName,
      String operator) {
    requireCreateNamespacePermissionForUserToken(appId, env, clusterName, null);
    namespaceOpenApiService.createMissingNamespaces(appId, env, clusterName,
        resolveOperator(operator, null));
    return ResponseEntity.ok().build();
  }

  private void validateCreateAppNamespaceRequest(String appId, OpenAppNamespaceDTO appNamespace) {
    RequestPrecondition.checkArguments(appNamespace != null,
        "app namespace payload can not be empty");
    if (!Objects.equals(appId, appNamespace.getAppId())) {
      throw new BadRequestException("AppId not equal. AppId in path = %s, AppId in payload = %s",
          appId, appNamespace.getAppId());
    }
    RequestPrecondition.checkArgumentsNotEmpty(appNamespace.getAppId(), appNamespace.getName(),
        appNamespace.getFormat());

    if (!InputValidator.isValidAppNamespace(appNamespace.getName())) {
      throw BadRequestException
          .invalidNamespaceFormat(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & "
              + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE);
    }

    if (!ConfigFileFormat.isValidFormat(appNamespace.getFormat())) {
      throw BadRequestException.invalidNamespaceFormat(appNamespace.getFormat());
    }
  }

  public boolean canCreateAppNamespace(String appId, OpenAppNamespaceDTO appNamespace) {
    if (!UserIdentityConstants.USER.equals(UserIdentityContextHolder.getAuthType())) {

View on GitHub (pinned to d95fc18d11)