PHP code example of hedii / zotero-api

1. Go to this page and download the library: Download hedii/zotero-api 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/ */

    

hedii / zotero-api example snippets



// '/path/to/vendor/autoload.php';

// instantiate
$api = new Hedii\ZoteroApi\ZoteroApi('your_zotero_api_key_here');

$api->user($userId)
    // continue chaining methods...

$api->group($groupId)
    // continue chaining methods...

$api->user($userId)
    ->items()
    // continue chaining methods...

$api->user($userId)
    ->items($itemKey)
    // continue chaining methods...

$api->user($userId)
    ->items()
    ->top()
    // continue chaining methods...

$api->user($userId)
    ->items()
    ->trash()
    // continue chaining methods...

$api->user($userId)
    ->items($itemKey)
    ->children()
    // continue chaining methods...

$api->user($userId)
    ->items($itemKey)
    ->tags()
    // continue chaining methods...

$api->user($userId)
    ->collections()
    // continue chaining methods...

$api->user($userId)
    ->collections($collectionKey)
    // continue chaining methods...

$api->user($userId)
    ->collections($collectionKey)
    ->items()
    // continue chaining methods...

$api->user($userId)
    ->collections($collectionKey)
    ->items()
    ->top()
    // continue chaining methods...

$api->user($userId)
    ->collections($collectionKey)
    ->tags()
    // continue chaining methods...

$api->user($userId)
    ->collections($collectionKey)
    ->subCollections()
    // continue chaining methods...

$api->user($userId)
    ->items()
    ->versions()
    // continue chaining methods...

$api->user($userId)
    ->tags()
    // continue chaining methods...

$api->user($userId)
    ->tags($tagName)
    // continue chaining methods...

$api->user($userId)
    ->searches()
    // continue chaining methods...

$api->user($userId)
    ->searches($searchKey)
    // continue chaining methods...

$response = $api->key($apiKey)
    ->send();
    
$keyPrivileges = $response->getBody();

$response = $api->user($userId)
    ->groups()
    ->send()
    
$groups = $response->getBody();

$api->user($userId)
    ->items()
    ->sortBy('publicationTitle')
    // continue chaining methods...

$api->user($userId)
    ->items()
    ->sortBy('language')
    ->direction('desc')
    // continue chaining methods...

$api->user($userId)
    ->items()
    ->limit(70)
    // continue chaining methods...

$api->user($userId)
    ->items()
    ->start(60)
    ->limit(70)
    // continue chaining methods...

$api->setTimeout(3000)
    // continue chaining methods...

$timeout = $api->getTimeout();

$api->setConnectionTimeout(3000)
    // continue chaining methods...

$connectionTimeout = $api->getConnectionTimeout();

$response = $api->user($userId)
    ->items()
    ->send();

$response = $api->user($userId)
    ->items()
    ->send();
    
$body = $response->getBody(); // array

$response = $api->user($userId)
    ->items()
    ->send();
    
$json = $response->getJson(); // string

$response = $api->user($userId)
    ->items()
    ->send();
    
$headers = $response->getHeaders(); // array

$response = $api->user($userId)
    ->items()
    ->send();
    
$statusCode = $response->getStatusCode(); // int

$response = $api->user($userId)
    ->items()
    ->send();
    
$reasonPhrase = $response->getReasonPhrase(); // string

$response = $api->raw('https://api.zotero.org/users/12345/items?limit=30&start=10')
    ->send();
    
$items = $response->getBody();



// _DIR__ . '/vendor/autoload.php';

use Hedii\ZoteroApi\ZoteroApi;

// instantiate zotero api
$api = new ZoteroApi('xxxxxxxxxxxxxxxxxxx');


// get the item 'ABCDEF' in the user 12345 library
$response = $api->user(12345)
    ->items('ABCDEF')
    ->send();
    
$item = $response->getBody();


// get 12 first top items in the group 12345 library and
// sort them by descendant modification date.
$response = $api->group(12345)
    ->items()
    ->top()
    ->limit(12)
    ->sortBy('dateModified')
    ->direction('desc')
    ->send();

$items = $response->getBody();


// search for tags matching 'a name' in the user 12345 library
$response = $api->user(12345)
    ->tags('a name')
    ->send();
    
$tags = $response->getBody();
  
    
// get all user 12345 collections
$response = $api->user(12345)
    ->collections()
    ->send();

$collections = $response->getBody();
    
    
// get top items within the collection 'ABCDEF' in the group 98765 library
$response = $api->group(98765)
    ->collections('ABCDEF')
    ->items()
    ->top()
    ->send();
    
$topItems = $response->getBody();

// get an array of all items keys with their versions
$response = $api->user(12345)
    ->items()
    ->versions();
    
$itemKeysWithVersions = $response->getBody();