{"record":{"id":"c75727690045b923","repo":"apolloconfig/apollo","slug":"params-appid-can-not-be-empty","errorCode":null,"errorMessage":"Params(AppId) can not be empty.","messagePattern":"Params\\(AppId\\) can not be empty\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java","lineNumber":390,"sourceCode":"  @Override\n  @PreAuthorize(value = \"@unifiedPermissionValidator.isSuperAdmin()\")\n  public ResponseEntity<Object> getConsumerTokenByAppId(String appId) {\n    requirePortalUserRequest();\n    return ResponseEntity.ok(consumerService.getConsumerTokenByAppId(appId));\n  }\n\n  @Override\n  @PreAuthorize(value = \"@unifiedPermissionValidator.isSuperAdmin()\")\n  public ResponseEntity<List<Object>> assignRoleToConsumer(String token, String type, Object body,\n      String envs) {\n    requirePortalUserRequest();\n    NamespaceDTO namespace = convertBody(body, NamespaceDTO.class);\n    List<ConsumerRole> consumerRoles = new ArrayList<>(8);\n    String appId = namespace.getAppId();\n    String namespaceName = namespace.getNamespaceName();\n\n    if (StringUtils.isEmpty(appId)) {\n      throw new BadRequestException(\"Params(AppId) can not be empty.\");\n    }\n    if (Objects.equals(\"AppRole\", type)) {\n      return ResponseEntity.ok(asObjects(Collections\n          .singletonList(consumerService.assignAppRoleToConsumer(token, appId, currentUserId()))));\n    }\n    if (StringUtils.isEmpty(namespaceName)) {\n      throw new BadRequestException(\"Params(NamespaceName) can not be empty.\");\n    }\n    if (envs != null) {\n      for (String env : envs.split(\",\")) {\n        if (StringUtils.isEmpty(env)) {\n          continue;\n        }\n        parseEnv(env);\n        consumerRoles.addAll(consumerService.assignNamespaceRoleToConsumer(token, appId,\n            namespaceName, env, currentUserId()));\n      }\n      return ResponseEntity.ok(asObjects(consumerRoles));","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java#L372-L408","documentation":"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.","triggerScenarios":"A POST to the consumer role-assignment endpoint (assignRoleToConsumer) with a JSON body whose appId field is missing, null, or an empty string.","commonSituations":"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.","solutions":["Include a non-empty appId in the request body JSON, e.g. {\"appId\":\"myApp\", \"namespaceName\":\"application\"}.","Verify the Content-Type header is application/json so Jackson maps the body to NamespaceDTO correctly.","Check for field-name casing — Apollo's NamespaceDTO uses camelCase appId."],"exampleFix":"// before\nPOST /consumer/createConsumerRole\n{}\n\n// after\nPOST /consumer/createConsumerRole\n{\"appId\":\"myApp\",\"namespaceName\":\"application\"}","handlingStrategy":"validation","validationCode":"// Validate body before sending\nNamespaceDTO body = new NamespaceDTO();\nbody.setAppId(appId);\nif (StringUtils.isEmpty(body.getAppId())) {\n  throw new IllegalArgumentException(\"appId must not be empty\");\n}","typeGuard":"function hasValidAppId(body: unknown): body is { appId: string } {\n  return typeof body === 'object' && body !== null\n    && typeof (body as any).appId === 'string'\n    && (body as any).appId.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always validate required fields client-side before POSTing.","Use typed request models (TypeScript interfaces, Java DTOs) to catch missing fields at compile time.","Log the request body in dev to confirm field mapping."],"tags":["validation","openapi","bad-request","consumer","apollo-portal"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}