{"record":{"id":"4e37c21b5e3065d3","repo":"apolloconfig/apollo","slug":"appid-not-equal-appid-in-path-s-appid-in-payl-4e37c2","errorCode":null,"errorMessage":"AppId not equal. AppId in path = %s, AppId in payload = %s","messagePattern":"AppId not equal\\. AppId in path = (.+?), AppId in payload = (.+?)","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java","lineNumber":256,"sourceCode":"        .ok(namespaceOpenApiService.findMissingNamespaces(appId, env, clusterName));\n  }\n\n  @PreAuthorize(value = \"@unifiedPermissionValidator.hasCreateNamespacePermission(#appId)\")\n  @ApolloAuditLog(type = OpType.CREATE, name = \"Namespace.createMissingNamespaces\")\n  @Override\n  public ResponseEntity<Void> createMissingNamespaces(String appId, String env, String clusterName,\n      String operator) {\n    requireCreateNamespacePermissionForUserToken(appId, env, clusterName, null);\n    namespaceOpenApiService.createMissingNamespaces(appId, env, clusterName,\n        resolveOperator(operator, null));\n    return ResponseEntity.ok().build();\n  }\n\n  private void validateCreateAppNamespaceRequest(String appId, OpenAppNamespaceDTO appNamespace) {\n    RequestPrecondition.checkArguments(appNamespace != null,\n        \"app namespace payload can not be empty\");\n    if (!Objects.equals(appId, appNamespace.getAppId())) {\n      throw new BadRequestException(\"AppId not equal. AppId in path = %s, AppId in payload = %s\",\n          appId, appNamespace.getAppId());\n    }\n    RequestPrecondition.checkArgumentsNotEmpty(appNamespace.getAppId(), appNamespace.getName(),\n        appNamespace.getFormat());\n\n    if (!InputValidator.isValidAppNamespace(appNamespace.getName())) {\n      throw BadRequestException\n          .invalidNamespaceFormat(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + \" & \"\n              + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE);\n    }\n\n    if (!ConfigFileFormat.isValidFormat(appNamespace.getFormat())) {\n      throw BadRequestException.invalidNamespaceFormat(appNamespace.getFormat());\n    }\n  }\n\n  public boolean canCreateAppNamespace(String appId, OpenAppNamespaceDTO appNamespace) {\n    if (!UserIdentityConstants.USER.equals(UserIdentityContextHolder.getAuthType())) {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java#L238-L274","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set appNamespace.setAppId(appId) to the same value used in the path before sending.","Validate the two values match client-side before the request (assertObjects.equals(pathAppId, dto.getAppId())).","If creating app namespaces for several apps, build a fresh DTO per app rather than mutating one shared instance.","Check the OpenAPI spec/model field name if integrating generated code (appId vs appId property)."],"exampleFix":"// before\nString pathAppId = \"appA\";\nOpenAppNamespaceDTO dto = templateFromAppB; // dto.appId = appB\nclient.createAppNamespace(pathAppId, dto); // 400 AppId not equal\n\n// after\ndto.setAppId(pathAppId);\nclient.createAppNamespace(pathAppId, dto);","handlingStrategy":"validation","validationCode":"// Validate path appId == body appId before the request.\nif (!Objects.equals(pathAppId, dto.getAppId())) {\n  dto.setAppId(pathAppId); // fix, or fail fast client-side\n}\nassert Objects.equals(pathAppId, dto.getAppId());","typeGuard":"null","tryCatchPattern":"try {\n  client.createAppNamespace(pathAppId, dto);\n} catch (HttpClientErrorException.BadRequest e) {\n  if (e.getResponseBodyAsString().contains(\"AppId not equal\")) {\n    dto.setAppId(pathAppId); client.createAppNamespace(pathAppId, dto);\n  }\n}","preventionTips":["Always set body.appId from the path variable, never from a separate template.","Build a fresh DTO per app when looping over multiple apps.","Add a client-side equality assertion before createAppNamespace."],"tags":["apollo-portal","openapi","bad-request","app-namespace","validation","appid"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}