+ Start a Discussion
Greg HGreg H 

Issue using the NetDocuments API - UpdateLookupTable

I am trying to integrate NetDocuments with Salesforce. Specifically, I am trying to pass a CSV formatted string to NetDocuments which will grant certain permissions on NetDocuments. The code with an issue is below:

public String createProjectAndSecurity(String sessionId) {
	String resultStatus;
	HttpRequest externalRequest = new HttpRequest();
	externalRequest.setMethod('POST');
	externalRequest.setEndpoint('https://vault.netvoyage.com/ndApi/storage.asmx');
	externalRequest.setHeader('Content-Type', 'text/xml; charset=utf-8');
	externalRequest.setHeader('SOAPAction', 'http://netdocuments.com/ndApi/UpdateLookupTable');//
	externalRequest.setHeader('Cookie', sessionId);
	String bodyString = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
	bodyString += '<soap:Body>';
	bodyString += '<UpdateLookupTable xmlns="http://netdocuments.com/ndApi/">';
	bodyString += '<repository>XX-XXXXXXXX</repository>';
	bodyString += '<emailAddr>greg@interactiveties.com</emailAddr>';
	bodyString += '<completionEmail>True</completionEmail>';
	bodyString += '<updateMode>add</updateMode>';
	bodyString += '<tableData>Project, Project Type, Project Closed, Project Access, Project Hold\nTESTING - 001,,,XYZ Company|VES,</tableData>';
	bodyString += '</UpdateLookupTable>';
	bodyString += '</soap:Body>';
	bodyString += '</soap:Envelope>';
	externalRequest.setBody(bodyString);
	Http http = new Http();
	try {
		HTTPResponse externalResponse = http.send(externalRequest);
		resultStatus = externalResponse.getStatus();
	} catch(System.CalloutException e) {
		//Exception handling goes here....
	}
	return resultStatus;
}

 

I keep receiving an internal server error response from NetDocuments. I am able to login to NetDocuments and get a session variable, which is what gets passed to this class and used in the request. I think the problem is with the value being passed in the tableData portion of the request but I am not sure. This tableData value should be a CSV formatted string.

 

Does anyone have any ideas?

-greg

BradleeBradlee

Hi Greg,

I see a couple of things. I believe you have a ticket open with us about this too but I just noticed more here than I did in the ticket. A couple of things to look at:

 

  • There is a space after each comma between attribute names in the header row of your table data string.
  • I'm not to familiar with what Apex is expecting for a new line, but I believe you'll want to use /r/n instead of /n.
  • Lastly, with our SOAP API, the authentication requires that you pass all set-cookies returned in the header through subsequent API calls. It looks like you're just passing the "sessionId" cookie and not the load balancer one that should also be returned in the login call.

Let us know if that doesn't clear up the error message for you.

Greg HGreg H

Thanks Bradlee. I do have a ticket open with NetDocuments for this issue but I wanted to see if any other developers may be able to help out as well.

 

I am not sure what you mean by the commas used in the header row of the data table string. Shouldn't they be there? Let me know and I can alter that if needed.

 

I have tried using the /r/n for the new line feed and that does not make a difference. Maybe it will if you clarify your first bullet?

 

The Set-Cookie is what I am using in the code. The variable name I am using in my Apex code is a bit misleading but I do grab the Set-Cookie from the login API response. An example that I just grabbed from a recent response is below:

BNI__BARRACUDA_LB_COOKIE=000000000000000000000000381e030a00005000; Path=/; Max-age=1800; HttpOnly;ASP.NET_SessionId=scup5k553eobtpqwoz30rxjt; path=/; secure; HttpOnly

 

I am using that entire string returned for the Set-Cookie header in subsequent calls but let me know if that should be altered.

 

I apreciate your help.

-greg

BradleeBradlee

Greg, yes it would be great if other Apex developers could help out too.

 

I apologize about my first bullet about the commas. I mis-wrote it and have now corrected that. What I think might be wrong is the spaces after the commas in the header row because those spaces are not there in the second row. Apologies for the confusion.

 

Thanks for the additional information about the cookies. That makes sense, let me run it by some others here to see if I'm missing anything else while you try taking out the spaces after the commas in the table data. Our developer told me, however, that this particular error message seems to point to something with the cookies vs. something related to the table data. It would be good to keep looking at both though :-) Let me know what you find and I'll do the same.

BradleeBradlee

Greg,

We don't have any in-house Apex developers, but this is what another of our developers suggested. I don't understand it fully but figured that you might.

 

"I would suggest he try importing document content instead of trying his own.  I think he is using C# from that example so I would suggest  bodyString += '<tableData> File.ReadAllText(filepath)</tableData>'; and see if that works."