최근 검색


최근 검색 없음

Piotr Pilat's Avatar

Piotr Pilat

가입한 날짜: 2024년 12월 07일

·

마지막 활동: 2024년 12월 17일

팔로잉

0

팔로워

0

총 활동 수

3

투표 수

0

가입 플랜

1

활동 개요

님의 최근 활동 Piotr Pilat

Piotr Pilat님이 에 댓글을 입력함

커뮤니티 댓글 Developer - Zendesk APIs

Well indeed im using it but lets say its not efficient way of fetching new articles. 
lets say you will have articles binded into multiple sections. than api shows the same article multiple times. (well at least that what im seeing on API side as i dont have access to “customer panel”  
my partial soluton is just filter by uuid of articles after fetching them all. but as i said is not efficent :) 
anyway thank you for your help :)) 

댓글 보기 · 2024년 12월 17일에 게시됨 · Piotr Pilat

0

팔로워

0

투표 수

0

댓글


Piotr Pilat님이 에 게시물을 만듦

게시물 Developer - Zendesk APIs

Hello, im doing integration for fetching zendesk articles within a given category. 
Problem is that i cannot see a effitient way to fetch Unique articles. 
Each article may be putted into multiple sections and category contains multiple section.

is there any efficent way to fetch unique articles in category without looping through each section in category and filtering by id?
such aproach uses multiple api calls and its not performance well.  below is my poor performance solution ;( i guess filtering such things like unique articles should be waay better done on your api side (or maybe is it but im doing wrong :P) 

"zendesk/zendesk_api_client_php": "^3.0"
 

    public function getArticlesByCategory(int $categoryId, int $page = 1, int $perPage = 25): array
    {
        try {
            $sectionsResponse = $this->client->helpCenter->sections()->findAll(['category_id' => $categoryId]);

            if (!isset($sectionsResponse->sections)) {
                $this->logger->error(self::API_RESPONSE_EMPTY);
                throw new InvalidDataException(
                    "No sections found for category ID: $categoryId",
                    Response::HTTP_BAD_REQUEST
                );
            }
            $sections = $sectionsResponse->sections;
            $allArticles = [];
            foreach ($sections as $section) {
                $articlesResponse = $this->client->helpCenter->articles()->findAll(['section_id' => $section->id]);

                if (isset($articlesResponse->articles)) {
                    foreach ($articlesResponse->articles as $article) {
                        $allArticles[$article->id] = $article;
                    }
                }
            }
            $uniqueArticles = array_values($allArticles);
            $offset = ($page - 1) * $perPage;
            $paginatedArticles = array_slice($uniqueArticles, $offset, $perPage);
        } catch (Throwable $e) {
            $this->logger->error($e->getMessage());
            throw new InvalidDataException($e->getMessage(), $e->getCode());
        }

        if (empty($paginatedArticles)) {
            $this->logger->error(self::API_RESPONSE_EMPTY);
            throw new InvalidDataException(
                "No articles found for category ID: $categoryId",
                Response::HTTP_BAD_REQUEST
            );
        }

        return $paginatedArticles;
    }

2024년 12월 07일에 편집됨 · Piotr Pilat

0

팔로워

2

투표 수

2

댓글