{"record":{"id":"ee54ea8bc8ae1c14","repo":"apolloconfig/apollo","slug":"the-app-id-of-path-variable-and-request-body-is-di","errorCode":null,"errorMessage":"The App Id of path variable and request body is different","messagePattern":"The App Id of path variable and request body is different","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/AppController.java","lineNumber":115,"sourceCode":"    accessKey.setMode(AccessKeyMode.FILTER);\n    accessKey.setEnabled(true);\n    accessKey.setDataChangeCreatedBy(operator);\n    return accessKey;\n  }\n\n  @DeleteMapping(\"/apps/{appId:.+}\")\n  public void delete(@PathVariable(\"appId\") String appId, @RequestParam String operator) {\n    App entity = appService.findOne(appId);\n    if (entity == null) {\n      throw NotFoundException.appNotFound(appId);\n    }\n    adminService.deleteApp(entity, operator);\n  }\n\n  @PutMapping(\"/apps/{appId:.+}\")\n  public void update(@PathVariable String appId, @RequestBody App app) {\n    if (!Objects.equals(appId, app.getAppId())) {\n      throw new BadRequestException(\"The App Id of path variable and request body is different\");\n    }\n\n    appService.update(app);\n  }\n\n  @GetMapping(\"/apps\")\n  public List<AppDTO> find(@RequestParam(value = \"name\", required = false) String name,\n      Pageable pageable) {\n    List<App> app;\n    if (StringUtils.isBlank(name)) {\n      app = appService.findAll(pageable);\n    } else {\n      app = appService.findByName(name);\n    }\n    return BeanUtils.batchTransform(AppDTO.class, app);\n  }\n\n  @GetMapping(\"/apps/{appId:.+}\")","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/AppController.java#L97-L133","documentation":"A BadRequestException (HTTP 400) thrown from AppController.update() (PUT /apps/{appId}) when the appId in the URL path variable does not match the appId in the JSON request body (App.getAppId()). Apollo validates that the resource identifier in the path and the entity body agree before persisting. This is a standard REST idempotency guard against accidental cross-resource updates.","triggerScenarios":"PUT request to /apps/{appId:.+} where the JSON body's appId field differs from the {appId} segment in the URL. For example, PUT /apps/myApp-001 with body {\"appId\":\"myApp-002\", ...}.","commonSituations":"Client builds the URL from one source and the body from another (e.g., different config files); a copy-paste error when updating app metadata; a frontend bug that uses a stale appId in the URL after the user switched apps.","solutions":["Ensure the appId in the URL path and the appId field in the request body are identical before sending.","Derive the URL path variable from the same dto.getAppId() value used in the body.","Validate client-side that the two match before issuing the PUT."],"exampleFix":"// before: URL and body may diverge\nString urlAppId = \"myApp-001\";\nApp app = new App();\napp.setAppId(\"myApp-002\"); // mismatch!\nrestTemplate.put(\"/apps/\" + urlAppId, app);\n\n// after: derive path from the same object\nrestTemplate.put(\"/apps/\" + app.getAppId(), app);","handlingStrategy":"validation","validationCode":"// Validate path and body appId match before sending\nif (!Objects.equals(pathAppId, app.getAppId())) {\n    throw new IllegalArgumentException(\"Path appId and body appId must match\");\n}\nappService.update(pathAppId, app); // or derive path from app.getAppId()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always derive the URL path variable from the same dto.getAppId() used in the request body.","Add a client-side assertion that path and body identifiers match before issuing PUT requests.","Avoid constructing the URL and body from independent configuration sources."],"tags":["validation","rest","path-variable","app","bad-request","apollo-adminservice"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}