1. Go to this page and download the library: Download landrok/yousign-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/ */
landrok / yousign-api example snippets
use Yousign\YousignApi;
/*
* token
*/
$token = '123456789';
$yousign = new YousignApi($token);
$users = $yousign->getUsers();
print_r(
$users->toArray()
);
foreach ($users as $user) {
/*
* For each User model, some methods are available
*/
// toArray(): to get all property values
print_r($user->toArray());
// get + property name
echo PHP_EOL . "User.id=" . $user->getId();
// property (read-only)
echo PHP_EOL . "User.id=" . $user->id;
// Some properties are models that you can use the same way
echo PHP_EOL . "User.Group.id=" . $user->getGroup()->getId();
echo PHP_EOL . "User.Group.id=" . $user->group->id;
// Some properties are collections that you can iterate
foreach ($user->group->permissions as $index => $permission) {
echo PHP_EOL . "User.Group.Permission.name=" . $permission->getName();
}
// At any level, you can call a toArray() to dump the current model
// and its children
echo PHP_EOL . "User.Group=\n";
print_r($user->group->toArray());
echo PHP_EOL . "User.Group.Permissions=\n";
print_r($user->group->permissions->toArray());
}
use Yousign\YousignApi;
/*
* Token
*/
$token = '123456789';
/*
* Production mode
*/
$production = false;
/*
* Instanciate API wrapper
*/
$yousign = new YousignApi($token, $production);
/*
* 1st step : send a file
*/
$file = $yousign->postFile([
'name' => 'My filename.pdf',
'content' => base64_encode(
file_get_contents(
dirname(__DIR__, 2) . '/tests/samples/test-file-1.pdf'
)
)
]);
/*
* 2nd step : create the procedure
*/
$procedure = $yousign->postProcedure([
"name" => "My first procedure",
"description" => "Awesome! Here is the description of my first procedure",
"members" => [
[
"firstname" => "John",
"lastname" => "Doe",
"email" => "[email protected]",
"phone" => "+33612345678",
"fileObjects" => [
[
"file" => $file->getId(),
"page" => 2,
"position" => "230,499,464,589",
"mention" => "Read and approved",
"mention2" => "Signed by John Doe"
]
]
]
]
]);
// toJson() supports all PHP json_encode flags
echo $procedure->toJson(JSON_PRETTY_PRINT);
use Yousign\YousignApi;
/*
* Token
*/
$token = '123456789';
/*
* Production mode
*/
$production = false;
/*
* Instanciate API wrapper
*/
$yousign = new YousignApi($token, $production);
/*
* Step 1 - Create your procedure
*/
$procedure = $yousign->postProcedure([
"name" => "My first procedure",
"description" => "Description of my procedure with advanced mode",
"start" => false,
]);
/*
* Step 2 - Add the files
*/
$file = $yousign->postFile([
'name' => 'Name of my signable file.pdf',
'content' => base64_encode(
file_get_contents(
dirname(__DIR__, 2) . '/tests/samples/test-file-1.pdf'
)
),
'procedure' => $procedure->getId(),
]);
/*
* Step 3 - Add the members
*/
$member = $yousign->postMember([
"firstname" => "John",
"lastname" => "Doe",
"email" => "[email protected]",
"phone" => "+33612345678",
"procedure" => $procedure->getId(),
]);
/*
* Step 4 - Add the signature images
*/
$fileObject = $yousign->postFileObject([
"file" => $file->getId(),
"member" => $member->getId(),
"position" => "230,499,464,589",
"page" => 2,
"mention" => "Read and approved",
"mention2" => "Signed By John Doe"
]);
/*
* Step 5 - Start the procedure
*/
$procedure = $yousign->putProcedure(
$procedure->getId(), [
"start" => true,
]
);
echo $procedure->toJson(JSON_PRETTY_PRINT);