passbolt/passbolt_api · error · CakeException

" " is not a valid resource id for filter .

Error message

"{0}" is not a valid resource id for filter {1}.

What it means

Thrown by QueryStringComponent::validateFilterResources when the key of an entry in a resource-id filter array is not an integer. Resource filters must be non-assoc, numerically indexed lists. The message interpolates the offending array key, so it may show a word instead of a value.

Solutions

  1. Use list syntax: filter[has-id][]=<uuid>.
  2. Reindex with array_values($values) before validating.
  3. Normalize or reject assoc filter maps at the client boundary.

Example fix

// before
GET /resources?filter[has-id][resource]=98c2bef5-cd5f-59e7-a1a7-0107c9a7cf08
// after
GET /resources?filter[has-id][]=98c2bef5-cd5f-59e7-a1a7-0107c9a7cf08
Defensive patterns

Strategy: validation

Validate before calling

if (!is_array($values)) { throw new \InvalidArgumentException('Filter must be an array.'); }
foreach (array_keys($values) as $k) {
    if (!is_int($k)) {
        throw new \InvalidArgumentException('Resource filter keys must be integers; use filter[has-id][]= syntax.');
    }
}

Type guard

function isIntKeyedList(mixed $values): bool {
    return is_array($values) && $values === array_values($values);
}

Try / catch

try {
    $ok = QueryStringComponent::validateFilterResources($values, $filterName);
} catch (\Cake\Core\Exception\CakeException $e) {
    throw new BadRequestException($e->getMessage());
}

Prevention

When it happens

Trigger: Passing an associative array such as ['resource' => $id] to validateFilterResources, e.g. ?filter[has-id][resource]=<uuid> instead of ?filter[has-id][]=<uuid>.

Common situations: Client builds filters as key/value maps; query-string syntax uses a named key; refactored code passes an assoc options array directly.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/17d98014ce7d183c. Report an issue: GitHub.

Appendix: source

Thrown at src/Controller/Component/QueryStringComponent.php:563

        return true;
    }

    /**
     * Validate a filter that is a single resource id
     * Examples:
     * - Bueno: '98c2bef5-cd5f-59e7-a1a7-0107c9a7cf08'
     * - No Bueno: 'no-bueno'
     *
     * @param array $values resources id
     * @param string $filterName name of filters
     * @throw CakeException if the filter is not valid
     * @return bool true if validate
     */
    public static function validateFilterResources(array $values, string $filterName): bool
    {
        foreach ($values as $i => $resourceId) {
            if (!is_int($i)) {
                throw new CakeException(__('"{0}" is not a valid resource id for filter {1}.', $i, $filterName));
            }
            if (!is_scalar($resourceId) || empty($resourceId)) {
                throw new CakeException(__('"{0}" is not a valid resource id for filter {1}.', $i));
            }
            if (!Validation::uuid($resourceId)) {
                $msg = __('"{0}" is not a valid resource id for filter {1}.', $resourceId, $filterName);
                throw new CakeException($msg);
            }
        }

        return true;
    }

    /**
     * Validate a filter that is a single group id
     * Examples:
     * - Bueno: '98c2bef5-cd5f-59e7-a1a7-0107c9a7cf08'
     * - No Bueno: 'no-bueno'

View on GitHub (pinned to 31c1bbc10f)