Try use php rest api to do text anchors esign, but got response of 1, signer did not receive any email
Monday, November 8, 2021 at 12:17pmHi,
New to onespan.
Below is my code to do the text anchor e-sign on my pdf
define("API_URL", "https://sandbox.esignlive.com/api/packages");
define("MULTIPART_BOUNDARY", "----WebKitFormBoundary1bNO60n7FqP5WO4t");
$api_headers = array(
"Authorization: Basic aDgxcvzxcvxcvzxczzxcbc01laURNTQ==",
"Accept: application/json; esl-api-version=11.0",
"Content-Type: multipart/form-data",
);
$json = array(
'type' => 'PACKAGE',
'status' => 'SENT',
'roles' => array(
array(
'id' => 'Signer1',
'type' => 'SIGNER',
'signers' => array(
array(
'email' => '[email protected]',
'firstName' => 'Frank',
'lastName' => 'Hu',
'id' => 'Signer1',
)
) ,
) ,
array(
'id' => 'Sender1',
'type' => 'SIGNER',
'signers' => array(
array(
'email' => '[email protected]',
'firstName' => 'John',
'lastName' => 'Smith',
'id' => 'Sender1',
)
) ,
) ,
) ,
'name' => 'Repipe Contract',
'documents' => array(
array(
//'id' => 'contract',
"name"=> "Repipe-Contract_all.pdf",
"index"=> 0,
'approvals' => array(
array(
"fields" => array (
array (
"type" => "SIGNATURE",
"extract"=> false,
"extractAnchor"=> array (
"text"=> "Signature",
"index"=> 0,
"width"=> 150,
"height"=> 40,
"anchorPoint"=> "TOPLEFT",
"characterIndex"=> 0,
"leftOffset"=> 0,
"topOffset"=> -50
),
"left"=> 0,
"subtype"=> "FULLNAME",
"top"=> 0
),
),
'role' => 'Signer1'
)
)
)
)
);
//var_dump(json_encode($json));exit;
$postdata = "--" . MULTIPART_BOUNDARY . "\r\n";
$postdata .= "Content-Disposition: form-data; name=\"file\"; filename=\"Repipe-Contract_all.pdf\"\r\n\r\n";
$postdata .= "Content-Type: application/pdf";
$postdata .= file_get_contents("/Applications/site/repipe_api/public/uploads/job/25/Repipe-Contract_all.pdf");
$postdata .= "\r\n\r\n";
$postdata .= "--" . MULTIPART_BOUNDARY . "\r\n";
//$postdata .= "Content-Disposition: form-data; name=\"payload\"\r\n\r\n";
$postdata .= json_encode($json);
//$postdata .= $json1;
$postdata .= "\r\n\r\n";
$postdata .= "--" . MULTIPART_BOUNDARY . "--\r\n";
$curl = curl_init(API_URL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST , true);
curl_setopt($curl, CURLOPT_POSTFIELDS , $postdata);
curl_setopt($curl, CURLOPT_HTTPHEADER , $api_headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($curl);
$response = curl_multi_getcontent($curl);
curl_close($curl);
echo mb_convert_encoding(print_r(json_decode($response, true), true), 'CP932', 'UTF-8');
but got response of 1, instand of ID, I was success when I do not asked for text anchor sign
Can anyone hlp on why?
Reply to: Try use php rest api to do text anchors esign, but got response of 1, signer did not receive any email
Monday, November 8, 2021 at 01:48pmHi Frank,
Welcome to OneSpan!
Not sure how your code is different from the code I attached below, but could you replace the API Key with your own and give it a quick attempt?
Duo
Reply to: Hi Frank, Welcome to…
Tuesday, November 9, 2021 at 03:48pmThanks Duo, your code works.
I found that it is caused by my PDF file, after change to new pdf file, my code also work.
Next, I need to implement multiple signatures for same person in one document and multiple documents
for multiple signature, is it just add multiple "fields"? for multiple documents, how to handle curl to attach multiple files?
Thanks again
Reply to: Thanks Duo, your code works…
Wednesday, November 10, 2021 at 08:26amHi Frank,
In order to create multiple signatures, you'd add more "approvals" nodes. Each of the approval node will contain a signature "fields" which defines the signature metadata (type, location, is required, etc), see below:
$json = array(
'type' => 'PACKAGE',
'status' => 'SENT',
'roles' => array(
array(
'id' => 'Signer1',
'type' => 'SIGNER',
'signers' => array(
array(
'email' => '[email protected]',
'firstName' => 'Frank',
'lastName' => 'Hu',
'id' => 'Signer1',
)
) ,
) ,
array(
'id' => 'Sender1',
'type' => 'SIGNER',
'signers' => array(
array(
'email' => '[email protected]',
'firstName' => 'John',
'lastName' => 'Smith',
'id' => 'Sender1',
)
) ,
) ,
) ,
'name' => 'Repipe Contract',
'documents' => array(
array(
//'id' => 'contract',
"name"=> "Repipe-Contract_all.pdf",
"index"=> 0,
'approvals' => array(
array(
"fields" => array (
array (
"type" => "SIGNATURE",
"extract"=> false,
"extractAnchor"=> array (
"text"=> "Signature",
"index"=> 0,
"width"=> 150,
"height"=> 40,
"anchorPoint"=> "TOPLEFT",
"characterIndex"=> 0,
"leftOffset"=> 0,
"topOffset"=> -50
),
"left"=> 0,
"subtype"=> "FULLNAME",
"top"=> 0
),
),
'role' => 'Signer1',
'id' => 'Signature1'
),
array(
"fields" => array (
array (
"type" => "SIGNATURE",
"extract"=> false,
"extractAnchor"=> array (
"text"=> "some other text anchor",
"index"=> 0,
"width"=> 150,
"height"=> 40,
"anchorPoint"=> "TOPLEFT",
"characterIndex"=> 0,
"leftOffset"=> 0,
"topOffset"=> -50
),
"left"=> 0,
"subtype"=> "FULLNAME",
"top"=> 0
),
),
'role' => 'Signer1',
'id' => 'Signature2'
)
)
)
)
);
To include multiple documents, please refer to my blog Upload Multiple Documents with REST, it showcased you how to compose the raw request.
Duo