hellosign / hellosign-python-sdk

A Python SDK for HelloSign's API
MIT License
29 stars 48 forks source link

Add get_url param to GET /signature_request/files/:signature_request_id #17

Closed alexmac05 closed 4 years ago

alexmac05 commented 8 years ago

Add get_url param to GET /signature_request/files/:signature_request_id

Endpoint: GET /signature_request/files/[:signature_request_id] The API documentation for this endpoint includes a parameter called: get_url

It is marked optional. It is a boolean. It goes on to say....."If true, the response will contain a url link to the file instead. Links are only available for PDFs and have a TTL of 3 days. (default = false)"

However,

python SDK https://github.com/HelloFax/hellosign-python-sdk/blob/v3/hellosign_sdk/hsclient.py line: 317 does not have a get_url parameter

If you try to use it then you get the following error message: TypeError: get_signature_request_file() got an unexpected keyword argument 'get_url'

alexmac05 commented 6 years ago

Workaround:

current_signatureRequestID = 'XXXXXXXXXXXXXXXXXX'

buildTheRequest = 'https://' + apikey + ':@api.hellosign.com/v3/signature_request/files/' \

r = requests.get(buildTheRequest) urlOfDocument = r.text urlOfDocument = urlOfDocument.replace("\","") print(urlOfDocument)

Create a substring from : to the end. But chop off : AND } and convert to a number and then do the convert call

getUTC = urlOfDocument.split(':')[3] getUTC = getUTC[:-1]

getURL = urlOfDocument.split('"')[3] print(getURL)

Figure out the UTC expires at value

print(convertUTCtoLocal(getUTC))

def convertUTCtoLocal(utcValue): if utcValue != None: print('nonempty time value given') return time.strftime("%Z - %Y/%m/%d, %H:%M:%S", time.localtime(float(utcValue))) else: return "Empty time value given"

jameschristopher commented 6 years ago

This works for me

import requests

def get_signature_request_file(signature_request_id, *args, **kwargs):
    path = 'https://api.hellosign.com/v3/signature_request/files/' + signature_request_id
    r = requests.get(path, params=kwargs, auth=(HELLOSIGN_API_KEY, ''))
    return r.json().get('file_url')

file_url = get_signature_request_file(signature_request_id, get_url=True)
oconnor-sn commented 4 years ago

Can this be closed, due to merge of PR 51

alexmac05 commented 4 years ago

@oconnor-sn and @neillom Testing this is not showing it working.

Example:

urlResponse = client.get_signature_request_file(
    signature_request_id='PUT_NUMBER_HERE',
    file_type="url",
    filename="test.pdf"
)

This does not work with or without filename="test.pdf" in the pass. I do think that filename is acting like it is required and that might be another issue with this fix. However, no combination that I can find is working to show that this fix is working for me.

To see it working in curl you can run this:

curl 'https://api.hellosign.com/v3/signature_request/files/Signature_Request_ID?get_url=1' \ -u 'API_KEY:'

that will return a ULR where you will need to change some of the slashes around to get it to display the file:

results

{"file_url":"https:\/\/s3.amazonaws.com\/hellofax_uploads\/super_groups\/2019\/12\/23\/45e55ebbf2de5e181e272577b7ea67d674f86592\/merged-tamperproofed.pdf?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAUMSXJYX53PFVNTGX%2F20191224%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20191224T002810Z&X-Amz-SignedHeaders=host&X-Amz-Expires=259200&X-Amz-Signature=XXXXXXXXXXXXXXXXXXXXXXXX","expires_at":1577406490}

Change that to: {"file_url":"https://s3.amazonaws.com/hellofax_uploads/super_groups/2019/12/23/45e55ebbf2de5e181e272577b7ea67d674f86592/merged-tamperproofed.pdf?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAUMSXJYX53PFVNTGX%2F20191224%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20191224T002810Z&X-Amz-SignedHeaders=host&X-Amz-Expires=259200&X-Amz-Signature=XXXXXXXXXXXXXXXXXXXXXXXX","expires_at":1577406490}

alexmac05 commented 4 years ago

This works in Python SDK version 3.8.9 and here is the syntax:

urlResponse = client.get_signature_request_file( signature_request_id='Signature_REQUEST_ID_HERE', response_type="url", )