Skip to content

Cannot get articles in specified category #559

Description

@edruid

The API docs indicate you should be able to GET /api/v2/help_center/categories/{category_id}/articles however I can't find a way to do this in this library. I would expect to find it in $zendeskHttpClient->helpCenter->categories($category_id)->articles()->iterator() but that doesn't exist. I tried $zendeskHttpClient->helpCenter->categories($category_id)->sections()->articles()->iterator() which gives all articles.

I think Zendesk\API\Resources\HelpCenter\Articles needs to be updated with something like (I tried it and it seems to work in my case, but I don't know what I'm missing)

    public function getRoute($name, array $params = [])
    {
        $lastChained = $this->getLatestChainedParameter();
        $params = $this->addChainedParametersToParams($params, [
            'section_id' => Sections::class,
        ]);
        if (empty($lastChained) || $name !== 'findAll') {
            return $this->localesGetRoute($name, $params);
        } else {
            $chainedResourceName = array_keys($lastChained)[0];
            $id = $lastChained[$chainedResourceName];
            if ($chainedResourceName === Sections::class) {
                $locales = $this->getLocale();
                if ($locales) {
                    return "{$this->prefix}{$locales}/sections/$id/articles.json";
                } else {
                    return "{$this->prefix}sections/$id/articles.json";
                }

            // This block is added:
            } elseif ($chainedResourceName === Categories::class) {
                $locales = $this->getLocale();
                if ($locales) {
                    return "{$this->prefix}{$locales}/categories/$id/articles.json";
                } else {
                    return "{$this->prefix}categories/$id/articles.json";
                }

            } else {
                return $this->localesGetRoute($name, $params);
            }
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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