{"record":{"id":"82af23397b066b7a","repo":"passbolt/passbolt_api","slug":"the-request-data-is-invalid-expected-a-collection","errorCode":null,"errorMessage":"The request data is invalid: expected a collection.","messagePattern":"The request data is invalid: expected a collection\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Rbacs/src/Model/Dto/RbacsUpdateDtoCollection.php","lineNumber":106,"sourceCode":"    {\n        return count($this->data);\n    }\n\n    /**\n     * Assert the whole data set is correct\n     *\n     * @throw BadRequestException if data is invalid\n     * @param array $data data [{id:<uuid>, control_function:<string>},...]\n     * @return void\n     */\n    public function assertdata(array $data): void\n    {\n        if (!count($data)) {\n            throw new BadRequestException(__('The request data is empty.'));\n        }\n        foreach ($data as $entry) {\n            if (!is_array($entry)) {\n                throw new BadRequestException(__('The request data is invalid: expected a collection.'));\n            }\n            $this->assertEntry($entry);\n        }\n\n        $this->assertUniqueIds($data);\n    }\n\n    /**\n     * Assert a given data entry\n     *\n     * @throw BadRequestException if entry doesn't match the expected format\n     * @param array $entry entry {id:<uuid>, control_function:<string>}\n     * @return void\n     */\n    public function assertEntry(array $entry): void\n    {\n        if (count($entry) > 2) {\n            throw new BadRequestException(__('The request data is invalid: invalid fields.'));","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Rbacs/src/Model/Dto/RbacsUpdateDtoCollection.php#L88-L124","documentation":"Structure guard in RbacsUpdateDtoCollection::assertdata(): one of the entries in the request data is not an array, i.e. the payload is not the expected collection of {id, control_function} objects, so a 400 is raised.","triggerScenarios":"Passing data where one or more items are scalars, strings, or null — e.g. [\"abc\"] or [null] instead of [[\"id\"=>..., \"control_function\"=>...]] — typically when the JSON body is a flat list of ids or malformed.","commonSituations":"Client sending [{\"id\": ...}] vs a bare array of id strings, JSON body structure mismatch after API change, or server-side callers passing decoded data of the wrong shape.","solutions":["Ensure every item in the request body is an object with id and control_function keys.","Fix the client payload structure to match [{\"id\":\"<uuid>\",\"control_function\":\"<string>\"}].","Validate payload shape before sending (e.g. JSON schema check).","On the server, decode the body as a JSON object list rather than a plain array."],"exampleFix":"// before\n[{\"d530aac7-...\"}, {\"9e3f5b2a-...\"}]\n// after\n[{\"id\":\"d530aac7-...\",\"control_function\":\"allow\"},{\"id\":\"9e3f5b2a-...\",\"control_function\":\"deny\"}]","handlingStrategy":"type-guard","validationCode":"if (array_filter($data, fn($e) => !is_array($e))) {\n    throw new InvalidArgumentException('each rbacs update entry must be an object');\n}","typeGuard":"function isRbacEntry(mixed $entry): bool {\n    return is_array($entry) && isset($entry['id'], $entry['control_function']);\n}\nif (!allEntriesAreRbacEntries($data)) { throw new InvalidArgumentException('bad payload'); }","tryCatchPattern":"try {\n    $collection = new RbacsUpdateDtoCollection($data);\n} catch (BadRequestException $e) {\n    // payload shape wrong: inspect entries\n}","preventionTips":["Serialize update entries as JSON objects, never bare id strings.","Validate payload against a JSON schema before sending.","Keep client payload builders in sync with the API contract."],"tags":["php","cakephp","rbacs","bad-request","payload-shape"],"backgroundTag":"unexpected-response-shape","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}