PHP code example of kazakevic / strapi-wrapper

1. Go to this page and download the library: Download kazakevic/strapi-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kazakevic / strapi-wrapper example snippets


$httpClient = new Client(); //Guzzle http client, but can be any suitable

$strapiClient = new StrapiClient(
$httpClient,
'token',
'http://localhost:1338'
);

$response = $strapiClient->getItems(
    'item-identifier',
    new PageFilter(100),
    new SortFilter('id', SortOrder::DESC)
);

$jsonData = $strapiClient->getItemById('seo-pages', 534546)

    $response = $strapiClient->getItemsBy(
        'item-identifier',
        'fieldName',
        'fieldValue',
        new PageFilter(100),
        new SortFilter('id', SortOrder::DESC)
    );

$jsonData = $strapiClient->createItem('topics', [

'data' => [
    'Title' => 'Test Title',
    'Slug' => 'test-slug',
    'seoTitle' => 'test title',
    'seoDescription' => 'test description',
    'tags' => [1, 2, 2],
    'videoCount' => 10
]
]);

$jsonData = $strapiClient->updateItem('topics', 1, [

'data' => [
    'Title' => 'Test Title',
    'Slug' => 'test-slug',
    'seoTitle' => 'test title',
    'seoDescription' => 'test description',
    'tags' => [1, 2, 2],
    'videoCount' => 10
]
]);