Docusign download unsigned enveloppe with tabs - docusignapi

Hello I'm using the docusign rest api and I have a use case where I must download an envelope document in pdf for manual signing the problem is when an envelope isn't signed I get the envelope document empty (without pre-filled fields) but when it's signed I get the document with all the fields,
the result expected is the document with all pre-filled fields.
Here is my code:
$curl = curl_init($loginInfo['baseUrl'] . "/envelopes/" . 'f487cf56-3a07-4cd3-ace7-XXXXXXXXXXXX' . "/documents" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
curl_close($curl);
//var_dump($xml);
//
// STEP 3 - download the documents
//
foreach( $response["envelopeDocuments"] as $document ) {
print_r($document);
$docUri = $document["uri"];
$curl = curl_init($loginInfo['baseUrl'] . $docUri );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"X-DocuSign-Authentication: $header" )
);
$data = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
file_put_contents('f487cf56-3a07-4cd3-ace7-XXXXXXXX' . "-" . $document["name"], $data);
curl_close($curl);
Thank you !

For people searching, you can't do it until the envelope is completed, the fields aren't attached to the document until it's signed.

Related

Telegram bot on IIS: sendPhoto is not working

function sendTelegramSMS($text,$tgimage) {
$botToken="tokenCODE";
$website="https://api.telegram.org/bot".$botToken;
$chatId='1242433';
//image
$params=[
'chat_id'=>$chatId,
'text'=> $text,
'photo'=> '#'.$tgimage,
];
$ch = curl_init($website . '/sendPhoto');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
//message
$params=[
'chat_id'=>$chatId,
'text'=> $text,
];
$ch = curl_init($website . '/sendMessage');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
}
$thefile= '/auth/prova.png';
sendTelegramSMS($reservation,$thefile);
This code works for sending messages (//message part), but doesn't work to send photos (//image part)...
i've tried a bounch of directory structure, nothing happen.
Hosted on Win10 with IIS.

Fetching signature image for logged in user using docusign rest api

I have a project in which I have created a form containing fileds:-
1.) Name
2.) Signature
In signature column there is button "Add Signature" when click on button it opens popup to enter docusign email and password. Once click on login it get's signature image url of the user. But the problem with my code is I am not getting image.
My issue is I want to display signature image after authentication in my project. Please suggest me what is wrong in my code.
My project url is:-
http://surgimedik.esoftech.in/out/out.AddDocument.phpfolderid=1&showtree=1#popup1
admin / admin
You can check below url where I am getting image url. when you hit it it asks for login itstead of showing image.
http://surgimedik.esoftech.in/docusign/test.phpemail=akash#esoftech.org&pwd=Terminate#12345
<?php
$email = $_REQUEST["email"];
$password = $_REQUEST["pwd"];
$integratorKey = '4a394221-7742-4f39-8a90-9021732676e8';
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
$url = "https://demo.docusign.net/restapi/v2/login_information?include_account_id=true";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$userId = $response["loginAccounts"][0]["userId"];
curl_close($curl);
$url_sig = "https://demo.docusign.net/restapi/v2/accounts/$accountId/users/$userId/signatures";
$curl_sig = curl_init($url_sig);
curl_setopt($curl_sig, CURLOPT_HEADER, false);
curl_setopt($curl_sig, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_sig, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response1 = curl_exec($curl_sig);
$status_sig = curl_getinfo($curl_sig, CURLINFO_HTTP_CODE);
if ($status_sig != 200) {
echo "error calling webservice, status is:" . $status_sig;
exit(-1);
}
$response1 = json_decode($json_response1, true);
$signatureId = $response1["userSignatures"][0]["signatureId"];
$url_sig1 = "https://demo.docusign.net/restapi/v2/accounts/$accountId/users/$userId/signatures/$signatureId";
$curl_sig1 = curl_init($url_sig1);
curl_setopt($curl_sig1, CURLOPT_HEADER, false);
curl_setopt($curl_sig1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_sig1, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response11 = curl_exec($curl_sig1);
$status_sig1 = curl_getinfo($curl_sig1, CURLINFO_HTTP_CODE);
if ($status_sig1 != 200) {
echo "error calling webservice, status is:" . $status_sig1;
exit(-1);
}
$result = json_decode($json_response11);
echo "https://appdemo.docusign.com" . $result->signatureImageUri;
You are using the wrong api.
Use the getImageUserSignatures api
GET /v2/accounts/{accountId}/users/{userId}/signatures/{signatureId}/signature_image

Import .pbix (power BI) file into the workspace using php (multipart form-data post)

I want to import local pbix fle to created workspace in azure power bi account. I already created workspaceId using REST API. However when i try to import pbix file that gives 200 ok status instead of 202 accepted response with Id.
Here is the reference code i followed enter link description here
POST https://api.powerbi.com/v1.0/collections/mypbiapp/workspaces/32960a09-6366-4208-a8bb-9e0678cdbb9d/imports?datasetDisplayName=mydataset01
Authorization: AppKey MpaUgrTv5e... Content-Type: multipart/form-data;
boundary="A300testx"
--A300testx Content-Disposition: form-data
{the content (binary) of .pbix file}
--A300testx--
I used php curl request to called Rest API and below shows the code which i tried,
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.powerbi.com/v1.0/collections/XXXXXX/workspaces/XXX-XXX-XXX-XXXXXXXX/imports?datasetDisplayName=mydataset01');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postData = array(
'datafile' => '#C:\Users\Desktop\report1.pbix',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
"Authorization: AppKey R97v4Fe5=="
) );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
echo $response = curl_exec($ch);
curl_close ( $ch );
As a response I'm getting status code as 200 ok with json
{"id":"0331a80d-6f23-4626-9624-1f6b98ce373a"}
However this new dataset was not created in workspaceID. Please help me to find the issue here.
Here is the answer for multipart form-data post with php curl, This code works for me
$name = 'report1';
$file = 'report1.pbix';
$boundary = "----------BOUNDARY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.powerbi.com/v1.0/collections/XXXXXX/workspaces/XXX-XXX-XXX-XXXXXXXX/imports?datasetDisplayName=mydataset01');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postdata .= "--" . $boundary . "\r\n";
$postdata .= "Content-Disposition: form-data; name=\"" . $name . "\"; filename=\"" . $file . "\"\r\n";
$postdata .= "Content-Type: application/octet-stream\r\n\r\n";
$postdata .= file_get_contents($file);
$postdata .= "\r\n";
$postdata .= "--" . $boundary . "--\r\n";
curl_setopt($ch, CURLOPT_POSTFIELDS, $$postdata);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
"Authorization: AppKey R97v4Fe5==",
'Content-Type: multipart/form-data; boundary='.$boundary,
'Content-Length: ' . strlen($postdata)
) );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
echo $response = curl_exec($ch);
curl_close ( $ch );
Here is a ready to use version of the given solution
public function import($access_key, $workspace_collection_name, $workspace_id, $file_path, $file_name, $display_name, $nameConflict = 'Overwrite')
{
$boundary = "----------BOUNDARY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.powerbi.com/v1.0/collections/$workspace_collection_name/workspaces/$workspace_id/imports?datasetDisplayName=$display_name&nameConflict=$nameConflict");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postdata = '';
$postdata .= "--" . $boundary . "\r\n";
$postdata .= "Content-Disposition: form-data; name=\"" . $file_name . "\"; filename=\"" . $file_path . "\"\r\n";
$postdata .= "Content-Type: application/octet-stream\r\n\r\n";
$postdata .= file_get_contents($file_path);
$postdata .= "\r\n";
$postdata .= "--" . $boundary . "--\r\n";
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: AppKey " . $access_key,
'Content-Type: multipart/form-data; boundary=' . $boundary,
'Content-Length: ' . strlen($postdata)
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_error($ch)) {
return 'curl error';
}
curl_close($ch);
return $response;
}

Docusign combine Embedded view and custom envelope with pdf

I am trying to combine the 2 API walkthrough examples but with the below code I get an authorization_invalid_request error.
Can anyone help me understand why that is?
Also I dont know if this is the optimal flow for it but what I want to accomplish is have the user sign a different document based on the pdf that is saved for that user in my local database and have the template dynamically created rather than have it predefined in docusign. Is there any better way of achieving that?
My code is:
<?php
class DocusignView {
public static function getEmbeddedSignView($signerName, $templateId, $templateRoleName, $clientUserId)
{
// Input your info:
$email = "***"; // your account email
$password = "***"; // your account password
$integratorKey = "***"; // your account integrator key, found on (Preferences -> API page)
$recipientName = '***'; // provide a recipient (signer) name
$templateId = '***'; // provide a valid templateId of a template in your account
$templateRoleName = 'Employee'; // use same role name that exists on the template in the console
$clientUserId = '1'; // to add an embedded recipient you must set their clientUserId property in addition to
// the recipient name and email. Whatever you set the clientUserId to you must use the same
// value when requesting the signing URL
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (retrieves baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
$envelopeId = DocusignView::requestSignByDoc($clientUserId);//$response["envelopeId"];
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Get the Embedded Singing View
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("returnUrl" => "http://www.docusign.com/devcenter",
"authenticationMethod" => "None", "email" => $email,
"userName" => $recipientName, "clientUserId" => $clientUserId
);
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$url = $response["url"];
//--- display results
return $url;
}
public static function requestSignByDoc($clientUserId){
// Input your info here:
$email = "***"; // your account email
$password = "***"; // your account password
$integratorKey = "***"; // your account integrator key, found on (Preferences -> API page)
$recipientName = "***"; // provide a recipient (signer) name
$documentName = "***.pdf"; // copy document with same name into this directory!
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (to retrieve baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
// echo "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with one recipient, one tab, and one document and send
/////////////////////////////////////////////////////////////////////////////////////////////////
// the following request body will place 1 signature tab on the document you supply, located
// 100 pixels to the right and 100 pixels down from the top left of the document
$data = array (
"emailSubject" => "DocuSign API - Signature Request on Document",
"documents" => array( array( "documentId" => "1", "name" => $documentName)),
"recipients" => array( "signers" => array(
array( "email" => $email,
"name" => $recipientName,
"recipientId"=> '1',
"clientUserId" => $clientUserId,
"tabs" => array(
"signHereTabs" => array(
array( "anchorString" => "Signed .....................................................",
"anchorXOffset" => "0",
"anchorYOffset" => "1",
"anchorIgnoreIfNotPresent"=> "false",
"anchorUnits" => "inches" )
))
))
),
"status" => "created"
);
$data_string = json_encode($data);
$temp = __DIR__.'/***.pdf';
$file_contents = file_get_contents($temp);
$requestBody = "\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data_string\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\"$documentName\"; documentid=1 \r\n"
."\r\n"
."$file_contents\r\n"
."--myboundary--\r\n"
."\r\n";
// *** append "/envelopes" to baseUrl and as signature request endpoint
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data;boundary=myboundary',
'Content-Length: ' . strlen($requestBody),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
return $envelopeId;
}
}
My JSON request:
"{
"returnUrl":"http:\/\/www.docusign.com\/devcenter",
"authenticationMethod":"None",
"email":"***",
"userName":"***",
"clientUserId":"1"
}"
My JSON response:
"{
"errorCode": "AUTHORIZATION_INVALID_REQUEST",
"message": "The authorization request is malformed."
}"
My authentication method is set to null but I had no problem running the embedded view example when I was not using the custom envelope(i.e. request sign by doc).
And heres an attempt using the API same problem with this one:
$docuSignClient = new DocuSign_Client();
$docuService = new DocuSign_ViewsService($docuSignClient);
$viewResource = new DocuSign_ViewsResource($docuService);
$signatureResource = new DocuSign_RequestSignatureResource($docuService);
$temp = __DIR__.'/test.pdf';
$file_contents = file_get_contents($temp);
$document[] = new DocuSign_Document('test.pdf', '1', $file_contents);
$recipient[] = new DocuSign_Recipient('1', '1', 'Signer1', 'recipientsEmail#email.com', '1', 'signers');
$envelopeId = $signatureResource->createEnvelopeFromDocument('TEST EMAIL SUBJECT', "PLease sign this", "created", $document, $recipient)->envelopeId;
$returnUrl = $request->getUri();
$url = $viewResource->getRecipientView($returnUrl, $envelopeId, 'Signer1', 'recipientsEmail#email.com', '1');
What am I missing?
So the bug was with the fact that the envelope is in a draft/created state and not sent! Makes sense but it took ages to figure out.

Clickbank api for getting the receipt information

I have tried creating a small class for clickbank which fetches the receipt information from the clickbank. I thought, it might be helpful for someone. In function get_payment_info($tries, $receipt) tries has been used because clickbank doesn't recognize transaction immediately after it happens.
<?php
define('CLICKBANK_DEV_KEY','DEV-KEY');
define('CLICKBANK_API_KEY','API-KEY');
Class ClickBank
{
/*
* $tries how many times to check for receipt
* because when you come back from clicbank it sometimes shows it invalid
*
* $receipt
*
* #return empty array if receipt not valid
* receipt info array if receipt is valid
*/
function get_payment_info($tries, $receipt){
$receipt_info = array();
while($tries>0 && count($receipt_info)==0){
$receipt_info = $this->get_receipt_info($receipt);
$tries--;
}
return $receipt_info;
}
function get_receipt_info($receipt){
$receipt_info = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.2/orders/$receipt");
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Authorization:".CLICKBANK_DEV_KEY.":".CLICKBANK_API_KEY));
$result = curl_exec($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
if($curl_info['http_code']==200){
$receipt_info = json_decode($result);
}
return $receipt_info;
}
}
$clickbank = new ClickBank();
$receipt = $_GET['cbreceipt'];
// it will return you transaction details
$transaction_info = $clickbank->get_payment_info(10, $receipt);

Resources