Skip to main content
1-Visitor
Jan 25, 2021 10:32 AM UTC
Question

Sending multipart request to external systems via ThingWorx service

Hi,

 

I want to send a multipart REST request to external system (out side the ThingWorx application) using a custom service, to send an xml file. This is the code snippet for the service-

There are no logs getting updated for the service execution, nor the request reaches the external system.

 

 

 var now = Date.now();
 var url = /*URL*/;
 /*jshint multistr: true */
 var body = /*XMLBODY*/

var table = Resources["InfoTableFunctions"].CreateInfoTable();

//Add new fields to the InfoTable:
table.AddField({name: "test", baseType: "XML"});

// add data row
table.AddRow({
 test: body
});

var params = {
	proxyScheme: undefined /* STRING */, 
	ignoreSSLErrors: true /* BOOLEAN */,
	useNTLM: undefined /* BOOLEAN */,
	partsToSend: table /* INFOTABLE */,
	workstation: undefined /* STRING */,
	useProxy: undefined /* BOOLEAN */,
	repository: <repoName> /* STRING */,
	proxyHost: undefined /* STRING */,
	url: url /* STRING */,
	timeout: undefined /* NUMBER */,
	proxyPort: undefined /* INTEGER */,
	password: undefined /* STRING */,
	pathOnRepository: <path> /* STRING */,
	domain: undefined /* STRING */,
	username: undefined /* STRING */,
 headers:{'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW',

 'X-XSRF-TOKEN':'TWX-XSRF-TOKEN-VALUE',
 }
};

// result: JSON
var result = Resources["ContentLoaderFunctions"].PostMultipart(params);
logger.info(" XMLRequestThing.SendXMLRequest(): Results From Calling Service - " + JSON.stringify(result));

 

 

Can some one please help with understanding what might be going wrong here, thank you!

4 replies

5-Regular Member
Jan 25, 2021 10:42 AM UTC

Hello @vaishnavee ,

 

The following community post might do the trick. Link here.

 

Hope it helps,

Translate
1-Visitor
Jan 25, 2021 11:10 AM UTC

Thanks for the reply, as suggested in the linked post, I have tried setting both the headers in my code - 

var params = {
	url: "http://www.example.com/api/yourservice" /* STRING */,
	partsToSend: table /* INFOTABLE */,
};
var params = {
	url: "http://www.example.com/api/yourservice" /* STRING */,
	repository: "FilesStorage" /* STRING */,
	pathOnRepository: "path/to/your/file/testfile.txt" /* STRING */,
};

Though this did not solve the problem for me.

Translate
Support
Jan 29, 2021 2:49 PM UTC

Hi @vaishnavee.

 

Have you tried using the Dev tools for troubleshooting the issue?  If you're not familiar with Dev tools, please check this article.

 

Have you validated that it's actually not connecting?  Please look at the external system for any logging from that side that may shed some light on the issue.

 

Regards.

 

--Sharon

 

 

Translate
Support
Feb 11, 2021 8:33 PM UTC

Hi @vaishnavee.

 

Were you able to find a solution for your problem?  If so, we would be very appreciative if you would post it here for the benefit of others in the community.

 

Regards.

 

--Sharon

Translate