Python – PUT data to a URL (Edit docusign recipient)

Wanted to submit a PUT request to a URL. The requests module in Python is the one recommended to do so. Can be easily downloaded using:

pip install requests

or

easy_install requests

More ways to install: http://docs.python-requests.org/en/latest/user/install/#install

Post installation, here’s a snippet to PUT data to a URL (this specific example shows how to Edit an existing docusign recipient):

#/usr/bin/python
import sys, json, urllib, urllib2, requests
import base64
 
# enter your info:
username = "username@org.com"
password = "YouP@ssword"
integratorKey = "YOUR-integration-key"

authenticateStr = "<DocuSignCredentials>" \
                    "<Username>" + username + "</Username>" \
                    "<Password>" + password + "</Password>" \
                    "<IntegratorKey>" + integratorKey + "</IntegratorKey>" \
                    "</DocuSignCredentials>"

# STEP 1 - Login
url = 'https://demo.docusign.net/restapi/v2/accounts/191919/envelopes/39d236e6-647c-4dac-b1ca-4b37b3ef9254/recipients'
payload = {
  "signers" :
  [
    {
      "email": "newrecipient@org.com",
      "name": "New Recipient",
      "recipientId": "2"
    }
  ]
}
headers = {'X-DocuSign-Authentication': authenticateStr, 'Accept': 'application/json'}
req = requests.put(url, data = json.dumps(payload), headers=headers)
print req
print req.status_code
print req.content
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s