Skip to content

Commit

Permalink
Demonstrate how to get help center articles by section_id (#536)
Browse files Browse the repository at this point in the history
- We need to wrap the client in a help center resource, otherwise the request
  will not have what it needs to retrieve all articles, rather than a given
  section
- Provide a specific example demonstrating how to list articles by section_id
  • Loading branch information
token-cjg committed Sep 23, 2024
1 parent 276fb53 commit 3a50ecd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion samples/helpcenter/findArticles.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

$client = new ZendeskAPI($subdomain);
$client->setAuth('basic', ['username' => $username, 'token' => $token]);
$help_center_client = new Zendesk\API\Resources\HelpCenter($client);

try {
// Find all helpcenter categories
$articles = $client->helpCenter->articles()->findAll();
$articles = $help_center_client->articles()->findAll();

echo "<pre>";
print_r($articles);
Expand Down
29 changes: 29 additions & 0 deletions samples/helpcenter/findArticlesBySectionId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require_once __DIR__ . '/../../vendor/autoload.php';

use Zendesk\API\HttpClient as ZendeskAPI;

/**
* Replace the following with your own.
*/

$subdomain = "subdomain";
$username = "email@example.com";
$token = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv";
$section_id = 10801195364239; // replace this with your section id

$client = new ZendeskAPI($subdomain);
$client->setAuth('basic', ['username' => $username, 'token' => $token]);
$help_center_client = new Zendesk\API\Resources\HelpCenter($client);

try {
// Find all helpcenter category with the given section id
$articles = $help_center_client->sections($section_id)->articles()->findAll();

echo "<pre>";
print_r($articles);
echo "</pre>";
} catch (\Zendesk\API\Exceptions\ApiResponseException $e) {
echo $e->getMessage().'</br>';
}

0 comments on commit 3a50ecd

Please sign in to comment.