$pccClientConfig = new \PccPhpSdk\core\PccClientConfig(
'--site-id-here--',
'--site-token-here--'
);
$pccClient = new \PccPhpSdk\core\PccClient($pccClientConfig);
$articlesApi = new \PccPhpSdk\api\ArticlesApi($pccClient);
$fields = ['id', 'snippet', 'slug', 'title'];
$articles = $articlesApi->getAllArticles($fields);
Here $fields
is optional. If we do not pass $fields
to get the selective fields, then it will return default fields in the resposnse.
We receive response as object of PccPhpSdk\api\Response\PaginatedArticles which can be used further.
Articles API allows to search for articles where the field(s) (body, tag, title) contains certain string.
$articlesApi = new ArticlesApi($pccClient);
$bodyContains = 'Test String';
$tagContains = 'Tag';
$titleContains = 'Sample Title';
$searchArgs = new ArticleSearchArgs(
$bodyContains,
$tagContains,
$titleContains,
PublishStatus::PUBLISHED
);
$fields = ['id', 'snippet', 'slug', 'title'];
$paginatedArticles = $articlesApi->getAllArticles(new ArticleQueryArgs(), $searchArgs, $fields);
Here $fields
is optional. If we do not pass $fields
to get the selective fields, then it will return default fields in the resposnse.
Here also we receive response as object of PccPhpSdk\api\Response\PaginatedArticles which can be used further.
Using Articles API we can also fetch the article by id or slug.
$contentApi = new ArticlesApi($pccClient);
$id = 'id-goes-here';
$fields = ['id', 'snippet', 'slug', 'title'];
$article1 = $articlesApi->getArticleById($id, $fields);
$slug = 'slug-goes-here';
$article2 = $articlesApi->getArticleBySlug($slug, $fields);
Here $fields
is optional. If we do not pass $fields
to get the selective fields, then it will return default fields in the resposnse.
Here the response is PccPhpSdk\api\Response\Article.
To view latest modifications of the article which are not published, we can use REALTIME
publishing level together with ArticlesAPI.
To get preview of the article use publishingLevel
argument as following.
$contentApi = new ArticlesApi($pccClient);
$id = 'id-goes-here';
$fields = ['id', 'snippet', 'slug', 'title'];
$article1 = $articlesApi->getArticleById($id, $fields);
$publishingLevel = \PccPhpSdk\api\Query\Enums\PublishingLevel::REALTIME;
$slug = 'slug-goes-here';
$article2 = $articlesApi->getArticleBySlug($slug, $fields, $publishingLevel);
Apart from reusing already created PCC Client created above, preview of the article can also be fetched without site token and by using the PCC Grant.
$pccClientConfig = new \PccPhpSdk\core\PccClientConfig(
'--site-id-here--',
'', // Leave this empty or use null
null,
'--pcc-grant-here--' // PCC Grant Token here, may or may not include pcc_grant prefix.
);
$pccClient = new \PccPhpSdk\core\PccClient($pccClientConfig);
$contentApi = new ArticlesApi($pccClient);
$id = 'id-goes-here';
$fields = ['id', 'snippet', 'slug', 'title'];
$article1 = $articlesApi->getArticleById($id, $fields);
$publishingLevel = \PccPhpSdk\api\Query\Enums\PublishingLevel::REALTIME;
$slug = 'slug-goes-here';
$article2 = $articlesApi->getArticleBySlug($slug, $fields, $publishingLevel);