1

I have this JSON file that DocuSign gives me as an example when getting user login information:

{
  "uri" : "https://demo.docusign.net/restapi/v2/login_information?api_password=true&include_account_id_guid=true&login_settings=all" ,
  "headers" : {
    "X-DocuSign-Authentication" : "{\Username\":\ ... " // Truncated due to sensitive 
                                                        // information
  }
}

Their API Exploration environment (using the sensitive information) then accesses the server and returns another JSON file with all of the login information of the user.

How does docusign do this using a GET method? I'm trying to accomplish these requests using PHP.

Jodo1992
  • 745
  • 2
  • 10
  • 32
  • what exactly is your question? maybe little more explanation would help – Harkirat Saluja Jun 07 '16 at 19:34
  • I am trying to get information from the DocuSign API through `GET` methods, but am very unsure how. Also, the JSON file above was the example that DocuSign used under "Request Options" in the "Get login information" `GET` method. The exploration environment can be found here: http://iodocs.docusign.com – Jodo1992 Jun 07 '16 at 19:37

1 Answers1

1

I believe it's just an example on their page that just so happens to represent the data in JSON format, probably because it's familiar to most web developers. You could do some fancy json decoding to programmatically insert the values into your request if you're receiving that JSON through another API, but that's probably more than most people need to do.

You are sending a payload via GET for all parameters after the question mark in the URL

?api_password=true&include_account_id_guid=true&login_settings=all

You're providing the authentication credentials as a header.

<?php

$uri = 'https://demo.docusign.net/restapi/v2/login_information?api_password=true&include_account_id_guid=true&login_settings=all';
$headers = 'X-DocuSign-Authentication: {"Username":"","Password":"","IntegratorKey":""}';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$uri);

curl_setopt($ch, CURLOPT_HTTPHEADER, array($headers));

curl_exec ($ch);

curl_close ($ch);

This gives me an expected response because I have no username account:

{ "errorCode": "PARTNER_AUTHENTICATION_FAILED", "message": "The specified Integrator Key was not found or is disabled. An Integrator key was not specified." }


Bonus

In their "Get Token" method via POST, the "body" refers to the POST payload. So first you would indicate to curl that it's a POST request with the CURLOPT_POST, and then set the value of "body" to the CURLOPT_POSTFIELDS

<?php

$uri = 'https://demo.docusign.net/restapi/v2/oauth2/token';
$headers = array(
  'Accept: application/json',
  'Content-Type: application/x-www-form-urlencoded',
  'Content-Length: 60'
);
$body = 'username=&password=&client_id=&grant_type=password&scope=api';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$uri);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

curl_exec ($ch);

curl_close ($ch);
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
  • Where can I go to find all the different constants such as 'CURL_URL' for different queries? Can't seem to find documentation on the ones you used as your 'curl_setopt ()' perameters. – Jodo1992 Jun 07 '16 at 21:32
  • 1
    @Jodo1992 they are all listed here: http://php.net/manual/en/function.curl-setopt.php – Jeff Puckett Jun 07 '16 at 21:33
  • I'm sorry to be a pest, but could you show the code for one more example? I'm having a hard time understanding how "body" fits in in the "Get Token" method via POST. There is no parameter `CURLOPT_BODY`. I have tried `CURLOPT_COOKIE` but that did not work either. – Jodo1992 Jun 07 '16 at 21:50
  • Is there any reason why (when copying your code and applying my information) I am not getting any return in the terminal whatsoever? – Jodo1992 Jun 09 '16 at 18:48
  • Hmm, works for me in the browser and terminal. But of course I don't have an account, so I get the obvious error message. What does it look like for you in their "try it" page? You will only see what's printed from the response body, so it's possible their sending you the return in the headers instead of the body, which would explain why it would be blank. To get the response headers, see this: http://stackoverflow.com/q/9183178/4233593 – Jeff Puckett Jun 09 '16 at 21:20
  • All PHP "try it" pages return the proper JSON format I'm looking for. PhpStorm's console is the only place that does not. – Jodo1992 Jun 09 '16 at 21:27
  • you'll get JSON responses on the "try it" pages in two different tabs: Response Headers and Response Body. which one contains the data in which you're interested? – Jeff Puckett Jun 09 '16 at 21:29
  • Response Body. When I run the code on PhpFiddle it works exactly as intended. It's just my PhpStorm is not. – Jodo1992 Jun 09 '16 at 21:34
  • I don't use phpstorm, so I'm really clueless. That seems like it would make a good question here though, or maybe http://superuser.com/ – Jeff Puckett Jun 09 '16 at 21:37