PHP code example of preprio / php-rest-sdk

1. Go to this page and download the library: Download preprio/php-rest-sdk 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/ */

    

preprio / php-rest-sdk example snippets




use Preprio\PhpRestSdk\Prepr;

$apiRequest = new Prepr('{ACCESS_TOKEN}');

$apiRequest
    ->path('content_items')
    ->query([
        'fields' => 'items'
    ])
    ->get();

if($apiRequest->getStatusCode() == 200) {

    print_r($apiRequest->getResponse());
}



use Preprio\PhpRestSdk\Prepr;

$apiRequest = new Prepr('{ACCESS_TOKEN}');

$apiRequest
    ->path('content_items/{id}', [
        'id' => '1236f0b1-b26d-4dde-b835-9e4e441a6d09'
    ])
    ->query([
        'fields' => 'items'
    ])
    ->get();

if($apiRequest->getStatusCode() == 200) {

    print_r($apiRequest->getResponse());
}

$apiRequest
    ->path('content_items')
    ->query([
        'limit' => 200 // optional
    ])
    ->autoPaging();

if($apiRequest->getStatusCode() == 200) {

    print_r($apiRequest->getResponse());
}

$apiRequest
    ->path('content_items')
    ->params([
        'body' => 'Example'
    ])
    ->post();

if($apiRequest->getStatusCode() == 201) {

    print_r($apiRequest->getResponse());
}

$apiRequest
    ->path('content_items')
    ->params([
        'body' => 'Example'
    ])
    ->put();

if($apiRequest->getStatusCode() == 200) {

    print_r($apiRequest->getResponse());
}

$apiRequest
    ->path('content_items/{id}',[
        'id' => "398402d-dd-asd-ads3343dad"
    ])
    ->delete();

if($apiRequest->getStatusCode() == 204) {

    // Deleted.
}

$apiRequest
    ->path('assets')
    ->params([
      'body' => 'Example',
    ])
    ->file('/path/to/file.txt')
    ->post();

if($apiRequest->getStatusCode() == 200) {

    print_r($apiRequest->getResponse());
}