PHP code example of blueink / blueink-client-php
1. Go to this page and download the library: Download blueink/blueink-client-php 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/ */
blueink / blueink-client-php example snippets
use Blueink\ClientSDK\Client;
// Provide the key directly...
$client = new Client('<YOUR_PRIVATE_API_KEY>');
// ...or set BLUEINK_PRIVATE_API_KEY in the environment and call:
// $client = new Client();
$response = $client->bundles->list();
foreach ($response->data as $bundle) {
echo $bundle['id'] . "\n";
}
$client = new Client(
private_api_key: 'sk_live_…',
base_url: 'https://sandbox.blueink.com/api/v2',
raise_exceptions: false,
);
$response = $client->bundles->retrieve('abc123');
$response->status; // int HTTP status code
$response->data; // mixed Decoded JSON body (associative array) or raw string
$response->headers; // array<string,string> Response headers (last value per name)
$response->pagination; // ?Pagination Parsed X-Blueink-Pagination header (list endpoints)
$response->originalResponse; // Psr\Http\Message\ResponseInterface
$last = $client->bundles->getLastResponse();
$response = $client->bundles->create([
'label' => 'A Test Bundle',
'is_test' => true,
'packets' => [[
'key' => 'signer-1',
'name' => 'Peter Gibbons',
'email' => '[email protected] ',
]],
'documents' => [[
'key' => 'doc-01',
'file_url' => 'https://example.com/contract.pdf',
'fields' => [],
]],
]);
$bundle_id = $response->data['id'];
use Blueink\ClientSDK\BundleHelper;
$bundle = new BundleHelper([
'label' => 'A Test Bundle',
'email_subject' => 'Please sign this test bundle',
'is_test' => true,
]);
// Add signers (each t build time), file path
// (streamed as multipart at request time), or raw HTML.
$doc_key = $bundle->addDocumentByURL('https://example.com/contract.pdf');
// $bundle->addDocumentByPath('/tmp/nda.pdf');
// $bundle->addDocumentByFile('/tmp/large.pdf', 'application/pdf');
// $bundle->addDocumentByHTML('<h1>Statement of Work</h1>...');
// Add a field at fixed coordinates, scoped to a list of editor packet keys.
$bundle->addField(
document_key: $doc_key,
x: 1, y: 15, w: 60, h: 6, p: 1,
kind: 'inp',
editors: [$signer1, $signer2],
label: 'Full name',
);
// Or let the API auto-place a field by searching the document text.
$bundle->addAutoPlacement(
document_key: $doc_key,
kind: 'sig',
search: 'Signature:',
w: 30, h: 6,
offset_x: 8, offset_y: -1,
editors: [$signer1],
);
$response = $client->bundles->createFromBundleHelper($bundle);
$signer = $bundle->addSigner(
name: 'Peter Gibbons',
email: '[email protected] ',
key: 'signer-1',
);
$tmpl_key = $bundle->addDocumentTemplate(
template_id: 'tmpl_abc123',
assignments: ['signer' => 'signer-1'], // role => signer key
initial_field_values: ['agree' => true], // field key => value
);
// Equivalent, post-hoc:
$bundle->assignRole($tmpl_key, 'signer-1', 'witness');
$bundle->setValue($tmpl_key, 'effective_date', '2026-01-01');
$response = $client->bundles->createFromBundleHelper($bundle);
$client->bundles->retrieve($bundle_id);
$client->bundles->retrieve($bundle_id, related_data: true); // attach events / files / data
$client->bundles->cancel($bundle_id);
$client->bundles->listEvents($bundle_id);
$client->bundles->listFiles($bundle_id);
$client->bundles->listData($bundle_id);
$client->bundles->createPreparationSession([
'allow_add_signers' => false,
'send_button' => ['text' => 'Submit'],
]);
use Blueink\ClientSDK\PersonHelper;
$helper = new PersonHelper(['name' => 'Jane Doe']);
$helper->addEmail('[email protected] ');
$helper->addPhone('+15551234567');
$created = $client->persons->createFromPersonHelper($helper);
$person_id = $created->data['id'];
$client->persons->retrieve($person_id);
$client->persons->update($person_id, ['metadata' => ['vip' => true]], partial: true);
$client->persons->delete($person_id);
$client->packets->update($packet_id, ['email' => '[email protected] ']);
$client->packets->embedURL($packet_id); // signed embedded-signing URL
$client->packets->retrieveCOE($packet_id); // Certificate of Evidence
$client->packets->remind($packet_id);
$client->templates->list();
$client->templates->retrieve($template_id);
$client->templates->delete($template_id);
$client->templates->createPreparationSession([
'allowed_data_flow_tags' => ['customer_name', 'acme:*'],
]);
$client->envelope_templates->list();
$client->envelope_templates->retrieve($envelope_template_id);
foreach ($client->envelope_templates->pagedList(per_page: 100) as $page) {
foreach ($page->data as $tpl) {
echo $tpl['id'] . "\n";
}
}
use Blueink\ClientSDK\BundleHelper;
$bundle = new BundleHelper([
'label' => 'Onboarding paperwork',
'is_test' => true,
]);
$bundle->addSigner(name: 'Peter Gibbons', email: '[email protected] ', key: 'signer-1');
$bundle->setEnvelopeTemplate(
template_id: 'env_tmpl_abc123',
field_values: ['company_name' => 'ACME Corp'],
);
$bundle->addEnvelopeTemplateFieldValue('start_date', '2026-01-15');
$response = $client->bundles->createFromEnvelopeTemplateHelper($bundle);
$created = $client->webhooks->create([
'name' => 'My integration',
'url' => 'https://example.com/blueink-webhook',
'event_types' => ['bundle_complete'],
]);
$client->webhooks->update($id, ['url' => '…'], partial: true);
$client->webhooks->delete($id);
// Custom request headers Blueink will send to your endpoint
$client->webhooks->createHeader([
'webhook' => $id,
'name' => 'X-My-Token',
'value' => 'shhh',
'order' => 0,
]);
// Verification of incoming deliveries
$client->webhooks->retrieveSecret();
$client->webhooks->regenerateSecret();
// Inspection
$client->webhooks->listEvents();
$client->webhooks->listDeliveries();
$client->webhooks->retrieveDelivery($delivery_id);
$response = $client->bundles->list(page: 1, per_page: 25);
$response->pagination->page_number;
$response->pagination->total_pages;
$response->pagination->per_page;
$response->pagination->total_results;
foreach ($client->bundles->pagedList(per_page: 100) as $page) {
foreach ($page->data as $bundle) {
// …
}
}
use Blueink\ClientSDK\BlueinkApiError;
try {
$client->persons->create(['name' => 'Jane Doe']);
} catch (BlueinkApiError $e) {
$e->status_code; // int HTTP status (also $e->getCode())
$e->detail; // ?string body.detail
$e->api_code; // ?string body.code (named api_code to avoid clashing with getCode())
$e->errors; // array<int,array{field?:string,message?:string}>
$e->body; // decoded body (array) or raw string when not JSON
$e->response; // ?Psr\Http\Message\ResponseInterface
$e->request; // ?Psr\Http\Message\RequestInterface
$e->getPrevious(); // GuzzleHttp\Exception\BadResponseException
foreach ($e->errors as $error) {
printf("%s: %s\n", $error['field'] ?? '_', $error['message'] ?? '');
}
}
$client = new Client(raise_exceptions: false);
$response = $client->persons->create(['name' => 'Jane Doe']);
if ($response->status >= 400) {
var_dump($response->data);
}
bash
composer