wesignature

Basic Oauth

OAuth allows you to perform actions on behalf of other users after they grant you the authorization to do so. For example, you could send signature requests on behalf of your users. This page lays out the basic steps to do that.

App Setup


Create an app Before you can do anything with OAuth, you will need to create an app.

Goto right header menu in your wesignature account. Click on Api's and goto create app tab and create an app for your application.

Field Description
Api app name App name can be anything but unique.
Domain name Specify the domain name for which you want to create an app without www.
Callback url Specify the default callback url oauth callback will be provided to this url. for eg (https://yourdomain/test).

Authorization

A user needs to authorize your app before you can act on his behalf. Once they do, your app will be granted an access token which can be used for authentication when making requests on behalf of your users.

For Oauth you have to include wesign oauth plugin button js to your footer scripts and this script also requires jquery. include this js script after jquery.

<script src="https://app.wesignature.com/library/front/js/wesign-button.js"></script>
$( "#button_id" ).wesign_button({ color: "orange", clientid:"*************", callback_url:"https://yourdomain/sample", state:"anything you want to set" });

After allowing for oauth signin. grant token and your provided state will be sent to you as get parameter on your callback url. grant token are short lived tokens that are used to generate accesstoken to be used for user behalf.



POST access token api
https://app.wesignature.com/oauth/generateAccessToken

Generates an access token with grant token.

The generated grant token send to this url as post parameter to get accesstoken for the user.

BODY jsondata

client_secret(required)
**************
client_id (required)
********************

Request

curl POST https://app.wesignature.com/oauth/generateAccessToken

-H 'Accept: application/json'

-H 'Content-Type: application/json'

"Grant-Code: *************"

-d '{ "client_id":"*****************", "client_secret": "*************" }'

Response

{
    "status":"success",
    "message":"token generated successfully",
    "data":{
        "access_token":"**************"
        }
}
                                            

Request

var form = new FormData();

form.append("sign_type", {sign type});

form.append("file", "/C:/Users/Dell/Desktop/army_image.jpg"));

form.append("client_id", "***************");

var settings = {

"async": true,

"crossDomain": true,

"url": "https://app.wesignature.com/api/generate_unclaimed_draft",

"method": "POST",

"headers": {

"Content-Type": "application/x-www-form-urlencoded",

"Authorization": "Bearer {token}",

},

"processData": false,

"contentType": false,

"mimeType": "multipart/form-data",

"data": form

}

$.ajax(settings).done(function (response) { console.log(response); });

Response

{
    "status":"success",
    "message":"document upload successfully",
    "data":
        {
            "signature_request_id":"group-1574072558383a731ead2b5e3b8f00f2196a4df85a","fileOrgname":"army_image.jpg",
            "filename":"1574072558383a731ead2b5e3b8f00f2196a4df85a.pdf"
        }
}
                                            

Request

$request = new HttpRequest();

$request->setUrl('https://app.wesignature.com/api/generate_unclaimed_draft');

$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(

'cache-control' => 'no-cache',

'Authorization' => 'Bearer {token}',

'Content-Type' => 'application/x-www-form-urlencoded',

'Authorization' => Bearer {Jwt token}'

'content-type' => 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' ));

$request->setBody('------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="sign_type" {sign_type} ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="file"; filename="army_image.jpg" Content-Type: image/jpeg ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="client_id" ***************** ------WebKitFormBoundary7MA4YWxkTrZu0gW--');

try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; }

Response

{
    "status":"success",
    "message":"document upload successfully",
    "data":
        {
            "signature_request_id":"group-1574072558383a731ead2b5e3b8f00f2196a4df85a",
            "fileOrgname":"army_image.jpg",
            "filename":"1574072558383a731ead2b5e3b8f00f2196a4df85a.pdf"
        }
}
                                            

Request

var fs = require("fs"); var request = require("request"); var options = { method: 'POST', url: 'https://app.wesignature.com/api/generate_unclaimed_draft', headers: { 'Postman-Token': '5a6fca02-9ac3-44e4-abf8-edc1edbc4142', 'cache-control': 'no-cache', Authorization: 'Bearer {token}', 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' }, formData: { sign_type: '{sign type}', file: { value: 'fs.createReadStream("/C:/Users/Dell/Desktop/army_image.jpg")', options: { filename: '/C:/Users/Dell/Desktop/army_image.jpg', contentType: null } }, client_id: '*************' } }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); });

Response

{
    "status":"success",
    "message":"document upload successfully",
    "data":
        {
            "signature_request_id":"group-1574072558383a731ead2b5e3b8f00f2196a4df85a","fileOrgname":"army_image.jpg",
            "filename":"1574072558383a731ead2b5e3b8f00f2196a4df85a.pdf"
        }
}
                                            


POST document send api
https://app.wesignature.com/api/get_embedded_unclaimed_draft

Generate a curl post request to the above api endpoint with required parameters. use jwt token as the authorization header.

Response json data

signature_request_id
unique document request id.
generate_draft_url
unclaimed draft url tobe used for assign signers positions in document.
BODY Json data

sign_type (required)
0(i sign),1(we sign),2(they sign)
file_url (required)
url of the file from where is tobe downloaded. example('https://yourdomain/wp-content/uploads/gfg-40.png')
client_id (required)
**************
is_for_embedded_signing (required)
0 (embedded and mail signing both),1 (embedded signing true),2 (only mail signing)
keep it 0, for i sign, sign_type
signers (required)
json containing name and email address of signers.
mail_data
json containing mail_subject and mail_message.

Request

curl POST https://app.wesignature.com/api/getSignatureRequestStatus

-H 'Accept: */*'

-H 'Authorization: Bearer {Jwt token}'

-H "content-type: application/json; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"

-d '{
    "sign_type": 3,
    "file_url": "https://domain_name/wp-content/uploads/gfg-40.png",
    "client_id": "*************",
    "is_for_embedded_signing": 0,
    "signers": [
        {
            "name": "bob",
            "email_address": "test12new@yopmail.com"
        },
        {
            "name": "test",
            "email_address": "test1@yopmail.com"
        }
    ],
    "mail_data":{
    	"mail_subject":"please sign",
    	"mail_message":"sign document immediately"
    }
}'

Response

{
    "status":"success",
    "message":"document data",
    "data":
    {
        "signature_request_id":"*************"
        "generated_draft_url":"{url}"
    }
    
}
                                            

The generated url in the response is to be put in the wesignature embed js to generate an embedded frame to sign documents like this. must include frame js and css.


<link href="https://app.wesignature.com/library/front/css/wesign_embed_frame.css" rel="stylesheet" type="text/css" />
                                
<script src="https://app.wesignature.com/library/front/js/wesign_embed_frame.js"></script>
var triggerButton = document.getElementById('trigger'); <script> triggerButton.addEventListener('click', function() { var myContent = document.getElementById('content'); var myModal = new WesignModal({ content: '{generated_draft_url}', client_id:'********************', }); myModal.open(); }); </script>


GET document status api
https://app.wesignature.com/api/get_signature_request?signature_request_id=*******

Generate a get request to the above api endpoint with required parameters. use jwt token as the authorization header.

Response Json data

Download link
available only when document is completed
Signer status
1 (pending), 2 (viewed),3 (signed and accepted),4 (rejected)
Document status
1 (out for signature),2 (cancelled),3 (completed)

Request

curl GET https://app.wesignature.com/api/get_signature_request?signature_request_id=*******

-H 'Accept: */*'

-H 'Authorization: Bearer {Jwt token}'

Response

{
    "status":"success",
    "message":"document data",
    "data":
    {
        "signature_request_id":"********","request_type":"1","is_embedded":"1","document_status":"1","signature_type":"3","client_id":"*******","userid":"**",
        "signer_data":
            [
                {
                    "signer_status":"1","signer_mail":"test12new@yopmail.com","signer_id":"******"
                },
                {
                    "signer_status":"3","signer_mail":"test1@yopmail.com","signer_id":"*****"
                }
            ]
    }
}
                                            

The document data is only generated when the document is send out for signature and the signer_id will generated only on an is_for_embedded_type 1 request to generate embedded frame for signing.




GET generate embedded signing url.
https://app.wesignature.com/api/get_embedded_signing_url?signer_id=********&is_modal=0

Generate a get request to the above api endpoint with required parameters. use jwt token as the authorization header.

Request GET parameters

signer_id
signer id got from the get signature request api for is_embedded 0 and 1 case.
is_modal
is_modal 0 for embedded popup signing (default 0) , 1 for a seperate url for signing in moblie app devices.
Response Json data

Data
Contains embedded signing url for wesign embed js

Request

curl GET https://app.wesignature.com/api/get_embedded_signing_url?signer_id=********&is_modal=1

-H 'Accept: */*'

-H 'Authorization: Bearer {Jwt token}'

Response

{
    "status":"success",
    "message":"document data",
    "data":"url"
}
                                        

The genrated url placed in wesign js will produce an iframe popup window for document signing.


<link href="https://app.wesignature.com/library/front/css/wesign_embed_frame.css" rel="stylesheet" type="text/css" />
                                
<script src="https://app.wesignature.com/library/front/js/wesign_embed_frame.js"></script>
var triggerButton = document.getElementById('trigger'); <script> triggerButton.addEventListener('click', function() { var myContent = document.getElementById('content'); var myModal = new WesignModal({ content: '{url}', client_id:'********************', }); myModal.open(); }); </script>


ERROR error codes

Application responds with these error codes, message and status in json format.

#Error Code Description
500 Internal server error.
401 Unauthorised.
200 Success in api's.
400 Parameters missing.