cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Sending multipart request to external systems via ThingWorx service

vaishnavee
12-Amethyst

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 4

Hello @vaishnavee ,

 

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

 

Hope it helps,

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.

slangley
23-Emerald II
(To:vaishnavee)

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

 

 

slangley
23-Emerald II
(To:slangley)

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

Top Tags