1

I'm new to both DocuSign and the Rest API. I'm attempting to familiarize myself with how DocuSign connects and downloads using a custom listener (in PHP) with the API Walkthrough located at http://iodocs.docusign.com/APIWalkthrough/getEnvelopeDocuments. I see that it downloads the PDF and the Certificate, but not the XML. I did a var_dump on the $data in the curl_exec and saw that it was all returned in a string with the XML present. My question is what's the best way to extract the XML data and why doesn't it download the XML file also? I apologize for any ignorance on my part. Thanks for any help and/or direction.

EDIT: My assumption is that it's returning a combined PDF, instead separate files (which is what we want). Is the index "envelopeDocuments" set in the RequestPDF function? In the API code I can't find this.

Ergin
  • 9,254
  • 1
  • 19
  • 28
duckie715
  • 165
  • 3
  • 13
  • Are you using DocuSign's REST API or the SOAP API? You started your question mentioning REST and you also link to the REST API Walkthroughs, but in your edit you reference the RequestPDF() call, which is from SOAP. – Ergin Aug 28 '13 at 16:35
  • Also, you can definitely download the documents individually or in combined fashion. The API Walkthrough that you've linked to does exactly that, is it not working for you? – Ergin Aug 28 '13 at 16:48

1 Answers1

0

The REST API Walkthrough that you have referenced is not related to DocuSign Connect at all. In the DocuSign platform there are two ways to get information about your envelopes - you can pull envelope data every so often, or you can have the envelope data pushed to you as they are completed, declined, etc. The walkthrough that you've referenced is the first method (i.e. it shows how to pull envelope data when you want). DocuSign Connect works in the reverse in that, based on how you configure it, it sends you data as events happen.

For starters, to configure Connect settings login to your account at demo.docusign.net, click your profile icon in the top right, and go to

Preferences -> Connect

On that page you will be able to select on of your Connect configurations (or create one if needed) and then configure for which users you want data pushed, on what events, and other settings.

In terms of setting up your listener, you can use any language that can successfully listen for http events (so your choice of PHP should be fine) but there's just a couple of things you'll need to ensure. For starters, you need to make sure you are listening or the proper port. In the DEMO system you can test on http (port 80) or https (port 443), but please note that in production (www.docusign.net) only https is allowed. Also note that you will not be able to test using a localhost URL. You need a real URL that can be reached from the outside world.

Your best bet for info and getting started is the page from the DocuSign Dev Center which describes Connect and links to it's guide. Please see here for more info:

http://www.docusign.com/developer-center/explore/connect

Ergin
  • 9,254
  • 1
  • 19
  • 28
  • Hi Ergin, thanks for responding to my questions. We have indeed setup Connect on our Demo environment. Currently we've enabled the log files, Include Documents, Include the Certificate, Require Acknowledgment, Sign with the X509 Certificate, and Include Document Fields. It's also set to Allow Publish. Our API is hosted on our MediaTemple server. We are indeed using REST. This is one of the areas I got a little confused on. I have been using cURL in my tests, so I suppose that is something that I have done right.The Walkthrough I was using does work, but it only pulls the two PDFs. – duckie715 Aug 29 '13 at 15:59
  • We're also getting a "remote server returned an error: (403) Forbidden" error from our server. I have an index page, all permissions are set correctly and the file ownership is also set correctly. Having not worked very much with XML, does this have any bearing on why we can't pull the XML file, because it doesn't have permission to write the file in the first place? – duckie715 Aug 29 '13 at 21:39
  • So I fixed the 403 error by just putting "Options +Indexes" in my .htaccess file. I also found that this was not the reason I can't get the XML file. I feel like I'm losing my mind over this. Am I suppose to create a data array in my listener to hold the XML when I pull the documents? We have twenty forms that applicants are suppose to fill out. If this is the case, I guess I'm lost on how to accomplish this for all those forms. – duckie715 Sep 03 '13 at 18:08
  • DocuSign Connect pushes data to your listener, so I'm not sure what you mean when you say "pull" the documents, but basically when Connect pushes data to your listener it will have an xml formatted body. This xml body is structured the same for all of your envelopes except that the content will change for each one of course. Try printing the whole response body that you receive and you'll see what it looks like, then you can create code that parses the elements you need and you'll only need to do it once. – Ergin Sep 03 '13 at 22:25
  • I guess I should have said "grab" instead of "pull". Sorry. This is all a bit frustrating for me since I haven't built a listener before. Most of the examples I seem to find are built on SOAP, so I'm still trying to figure out how do this with REST. – duckie715 Sep 05 '13 at 01:23
  • In other words, my knee-jerk reaction is to use an if statement to check if EnvelopeEventStatusCode == "Completed", but this is part of SOAP, so that's where I get lost. What would be the REST equivalent? – duckie715 Sep 05 '13 at 01:54
  • So I'm having the hardest time getting it to print out the response. In my cURL code, I'm setting the http header as `curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header", "Accept: text/xml", "Content-Type: text/xml"));`, but I'm receiving JSON back and it's not the actual document information. I also have the return transfer set as `curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);`. I'm losing my my mind! What am I doing wrong?! – duckie715 Sep 05 '13 at 18:39
  • Try application/xml instead of text/xml. And where are you now, are you at the point where you're receiving the push from DocuSign but you're trying to parse the response data now? – Ergin Sep 05 '13 at 18:43
  • So I changed all my http headers to application/xml, but now I'm getting "accountId = baseUrl = error calling webservice, status is this:0". During the login cURL request, should the header be set to `curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header", "Accept: application/xml", "Content-Type: application/xml"));`? When I have it set like this, I get the above error. When it's set to text/xml, I get no errors. When it's taken out, I get an index error on my foreach statement. – duckie715 Sep 05 '13 at 19:16
  • Also, our client wants to have us build an API for them to use in-house. Is it a pain to do using REST and cURL in PHP? Or would this be best suited to using SOAP? Also, my supervisor and I are attending next week's training in SF. Will any of this be covered during that second day? – duckie715 Sep 05 '13 at 21:37
  • After re-reading your original post I think there's some confusion here. The API Walkthrough that you've linked to is one way of getting your envelopes and documents, but that's not using DocuSign Connect, that's pulling data out of the system instead of having it pushed to your listener. You should take a step back and look at these two resources [DocuSign Connect Guide](http://www.docusign.com/sites/default/files/DocuSign_Connect_Service_Guide.pdf) and [Sample PHP listener in SDK](https://github.com/docusign/DocuSign-eSignature-SDK/tree/master/PHP/Connect) – Ergin Sep 05 '13 at 21:47
  • So the PHP listener example makes sense: the $postBackPath variable keeps an open channel so it can receive the event notifications that we set in the Connect setup on DocuSign, it then opens the URL, is set to accept content in the form of xml, post is set to true, it posts the fields from the $xml variable as xml. Then we basically write the file to the root directory where the listener is, correct? I guess where I'm a little stuck is getting the data. In the example, it's loading an xml file. Do I need to setup another REST/cURL call and replace the "post.sample" with this call? – duckie715 Sep 05 '13 at 22:34
  • You don't have to write the file to the root directory, I think the code does that for simplicity. It's your decision for where to write the file to. In terms of where you get the data, the data will be contained in the response body that the listener receives on each POST (in other words, the **$xml** variable). The sample post.sample file is just to show you what a sample response looks like. This should all work out of the box assuming everything's configured correctly... – Ergin Sep 05 '13 at 23:14
  • I understand all that. I know that I have to put a url in simplexml_load_file, but I don't know what that would be. – duckie715 Sep 06 '13 at 01:32
  • Also, when I go to DocuSign Connect Settings > DocuSign Connect Logs and view the latest log, the Response says it's returning HTML, from our index page. – duckie715 Sep 06 '13 at 01:34
  • Response is now returning the proper information. I just have to figure out how to have it take the response without setting up a variable with a known envelope ID. – duckie715 Sep 06 '13 at 14:52
  • So I got it to take the response and put the file in its on folder named from the envelope id. I just have to figure out how to parse it, which is something I've never done before. – duckie715 Sep 06 '13 at 23:19