PHP code example of cwd / datamolino-client

1. Go to this page and download the library: Download cwd/datamolino-client 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/ */

    

cwd / datamolino-client example snippets


$datamolino = new DatamolinoClient();

// Get a Token via password authentication
$token = $datamolino->getClient()->authenticatePassword($clientID, $clientSecret, $username, $password);

// Store the token for later use
// you can refresh your token any time by using
$token = $datamolino->getClient()->refreshToken($clientID, $clientSecret, $token->getRefreshToken());

// If you have stored the token elsewhere just build the object:
$token = (new Token())->setAccessToken($accessToken)
                      ->setRefreshToken($refreshToken)
                      ->setsetExpiresIn($expiresIn);

// Set the token in the Client
$datamolino->getClient()->setToken($token);

// me   
$user = $datamolino->user()->me();

// get all agendas
$agendas = $datamolino->agenda()->getAll();

// get agenda by id
$agenda = $datamolino->agenda()->get(4050);

// update
$agenda->setName('My Agenda Name')
       ->getAddress()->setBuildingNo(2);
$datamolino->agenda()->update($agenda);
    
// create    
$agenda = new Agenda();
$agenda->setName('My Other Agenda')
       ->setAddress((new Address())
            ->setStreet('Example')
            ->setBuildingNo(125)
            ->setCountry('at')
            );
$agenda = $datamolino->agenda()->create($agenda, $lacyLoad = true);
    
// delete    
$datamolino->agenda()->delete(4063);
 
// Find documents
$documents = $datamolino->document()->find(4050, [], new \DateTime('2018-10-10 21:59:21'));

// Get document by id
$document = $datamolino->document()->get(268145);

// Upload multiple documents via finder
$finder = (new Finder())->in('../testdata')->date('since 1 hour ago');
$documents = $datamolino->document()->createMultiple($finder, 4050, Document::DOCTYPE_PURCHASE, false, true);
// Or path
$documents = $datamolino->document()->createMultiple('../testdata', 4050, Document::DOCTYPE_PURCHASE, false, true);
// or supply an array with SPLFileInfo Objects
$files = [
    new \SplFileInfo('path/to/file.pdf'),
    new \SplFileInfo('path/to/other/file.pdf'),
];
$documents = $datamolino->document()->createMultiple($files, 4050, Document::DOCTYPE_PURCHASE, false, true);

// send repair request for a document
$datamolino->document()->repair(268138, 'API test ignore');

// Delete document
$datamolino->document()->delete(268145);

$datamolino = $this->get(Cwd\Datamolino\DatamolinoClient::class);

// Get a Token via password authentication
$token = $datamolino->getClient()->authenticate();