How to Send a pdf file to RightSignature via Private API Token?

  • 1
  • Question
  • Updated 1 month ago
Hi All,

I am new to RightSignature. I want to send a pdf file to RIghtSignature via this New Private API Token. Can you please help me to do this?
Photo of Justin Felix

Justin Felix

  • 4 Posts
  • 0 Reply Likes

Posted 1 month ago

  • 1
Photo of Saravanan Kannan

Saravanan Kannan, Employee

  • 32 Posts
  • 6 Reply Likes
Justin,

You could create a reusable template in the UI and use that to send a document https://api.rightsignature.com/documentation/resources/v1/reusable_templates/send_document.en.html or create a sending request to send one-off document https://api.rightsignature.com/documentation/resources/v1/sending_requests.en.html

Thanks
Saravanan
Photo of Justin Felix

Justin Felix

  • 4 Posts
  • 0 Reply Likes
I can see a upload url here, "upload_url": "https://rightsignature-sr-production.s3.amazonaws.comsending_requests/dbc73bba-2fe6-4a73-a227-3d221e... . Is this default one or It will be changed dynamically. And where can I add the Access Token with the Json. And my Code is like this.

<?php
$body = '{
  "file": {
    "name": "ZCG_Contract.pdf",
    "source": "upload"
  },
  "document": {
    "signer_sequencing": false,
    "expires_in": 12,
    "name": "Sign me",
    "roles": [
      {
        "name": "a",
        "signer_name": "Justin",
        "signer_email": "justin@aorborc.com"
      }
    ]
  },
  "sending_request": {}
}';


$curl = curl_init();

$token = base64_encode('27f8cb2609f65715008aa06161b4723bbe893d36ede3a9e757bc0871f3b7eb7f');
$endpoint = 'https://api.rightsignature.com/public/v1/reusable_templates';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$result = curl_exec($ch);
curl_close($ch);

?>

Here, No option to add Access Token. If we need to pass Access Token, What are the Parameters need to be added. Please help me to do this.

Thanks,
Justin Felix


(Edited)
Photo of Saravanan Kannan

Saravanan Kannan, Employee

  • 32 Posts
  • 6 Reply Likes
Justin,

That url in the documentation is an example url. It will be dynamic for every sending request. You should do a POST request to this end point /public/v1/sending_requests, not to the reusable templates. Then in the response we will provide you a upload url, to which you have to upload the document and trigger the document creation by doing a POST to this end point /public/v1/sending_requests/:id/uploaded Hope this helps.

Thanks
Saravanan
Photo of Justin Felix

Justin Felix

  • 4 Posts
  • 0 Reply Likes
Hi,

Your latest post is very helpful. I have understood something from that. I have tried what you have said. I got an exception "Invalid Token". I have used the base64 format of private token. I passed the Private Token in Json, But It threw Invalid Token Exception. Again I passed via Header, But It also did not work. 

My Code:

<?php

$url = 'https://api.rightsignature.com/public/v1/sending_requests';



$body ='{
  "access_token":"My Access Token",
  "file": {
    "name": "ZCG_Contract.pdf",
    "source": "upload"
  },
  "document": {
    "signer_sequencing": false,
    "expires_in": 12,
    "name": "Sign me",
    "roles": [
      {
        "name": "a",
        "signer_name": "Justin",
        "signer_email": "justin@aorborc.com"
      }
    ]
  },
  "sending_request": {}
}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/json", "Content-Type: text/json;charset=utf-8", "api-token: My Access Token"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$result = curl_exec($ch);
curl_close($ch);

echo $result;

?>

Is the parameter and passing the place is correct?

Thanks,
Justin Felix.

Photo of Saravanan Kannan

Saravanan Kannan, Employee

  • 32 Posts
  • 6 Reply Likes
Justin,

This is how you do the first step in creating a sending request:

$url = 'https://api.rightsignature.com/public/v1/sending_requests';
$token = base64_encode('YOUR PRIVATE API TOKEN GOES HERE');
$authorization = "Authorization: Basic ".$token;


$body ='{
  "file": {
    "name": "testSR.pdf",
    "source": "upload"
  },
  "document": {
    "signer_sequencing": false,
    "expires_in": 12,
    "name": "Sign me",
    "roles": [
      {
        "name": "a",
        "signer_name": "Justin",
        "signer_email": "email@test.com"
      }
    ]
  },
  "sending_request": {}
}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", $authorization, "Accept: application/json"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$result = curl_exec($ch);
print_r($result);
if (curl_errno($ch)) {
  print "Error: " . curl_error($ch);
}

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo 'HTTP code: ' . $httpcode;

$json = json_decode($result, true);
$sr_id = $json['sending_request']['id'];
$upload_url = $json['sending_request']['upload_url'];

Step 2:

Once you get the upload url from the above request, you make a PUT request with your file to that url.

Step 3:

You will make a POST request to /public/v1/sending_requests/:id/uploaded  with the sending request id, to trigger the upload process.

Step 4:
You can check the status of that document processing here by doing a GET /public/v1/sending_requests/:id

Hopefully, this helps.

Thanks
Saravanan