Skip to content

LinksAPI throws Exceptions #71

@UXfocusTomG

Description

@UXfocusTomG

I tried to get all the links using the Links API for a sitemap.

When calling the function all() two issues popped up:

→ When the LinksAPI creates the LinsResponse object the following Errors are thrown:

→ due to a missing field "total" in the response headers
-- InvalidArgumentException: Expected the key "total" to exist.
→ due to a missing field "alternates" in the values array:
-- InvalidArgumentException: Expected the key "alternates" to exist.

When commenting the following code lines everything works as expected:

  • LinksApi.php:
    Total::fromHeaders($response->getHeaders())
  • Links.php:
    Assert::keyExists($values, 'alternates'); Assert::isArray($values['alternates']); $this->alternates = array_map(static fn (array $values) => new LinkAlternate($values), $values['alternates']);

Maybe it is a problem with the API version?


Expected Behavior

Actually I expect the function to return all the links in my storyblok space

Current Behavior

Exception is thrown

Steps to Reproduce

$client = new StoryblokClient(
        baseUri: 'https://api.storyblok.com/v2/cdn',
        token: $apiKey,
        timeout: 10 // optional
    );
$linksApi = new LinksAPI($client);
$result = $linksApi→all();

→ Exceptions are thrown

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions