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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Post XML

AC_9552412
10-Marble

Post XML

hello, I need to make a post to thingworx with a XML parameter, I am trying to send it from postman and it is seen that the content of the parameter does not arrive to thingworx, I have a debug logger to see that it arrives and it always comes out undefined.

What can be the solution?

ACCEPTED SOLUTION

Accepted Solutions

Seeing there are two different suggested values for the "Content-Type" header, I would like to add a small correction to the reply above: the Content-Type should always be set to "application/json" in the context of that reply.

From another perspective, a relatively less known way to pass a value to a ThingWorx service is to specify the name of the input parameter as an URL parameter. The advantage of doing it in this way is you can simply post the value itself without needing to wrap it in a ThingWorx-specific JSON structure.

This is useful if whatever service calls ThingWorx does not have the capability to create that ThingWorx-specific JSON structure (as it's the case with almost all external systems that push data via REST to ThingWorx if you do not want to customize them)

URL: /Thingworx/Things/TestThing/Services/aa?postParameter=XMLParam

Method: POST

Content-Type: text/xml (as per this Help Center entry)

Body: <order id="i153420aaaadsd3"> <part id="p343-3456" quantity="2"/></order>

 

Note that Accept only formats the reply that ThingWorx will send to the calling system (you can omit and you'll get an HTML-formatted response).

View solution in original post

4 REPLIES 4

Hi @AC_9552412 

In Thingworx Post API Method is used to execute the service if you want to update the thing property value then use put method.

 

Please make sure you pass the application key in the header of the API request and change the Content-Type to application/XML

and in thingworx, your property or service parameter should be XML data type  service has inputData is service parameter 

 

 

for example use the below request payload

 

{
    "inputData""<inputData> <param1>VPostNam</param1> <param2>Value2</param2></inputData>"
}
 
and use the header parameter below:
 
'appKey: <your Application Key>
'Accept: application/json'
'Content-Type: application/json' 
 

Seeing there are two different suggested values for the "Content-Type" header, I would like to add a small correction to the reply above: the Content-Type should always be set to "application/json" in the context of that reply.

From another perspective, a relatively less known way to pass a value to a ThingWorx service is to specify the name of the input parameter as an URL parameter. The advantage of doing it in this way is you can simply post the value itself without needing to wrap it in a ThingWorx-specific JSON structure.

This is useful if whatever service calls ThingWorx does not have the capability to create that ThingWorx-specific JSON structure (as it's the case with almost all external systems that push data via REST to ThingWorx if you do not want to customize them)

URL: /Thingworx/Things/TestThing/Services/aa?postParameter=XMLParam

Method: POST

Content-Type: text/xml (as per this Help Center entry)

Body: <order id="i153420aaaadsd3"> <part id="p343-3456" quantity="2"/></order>

 

Note that Accept only formats the reply that ThingWorx will send to the calling system (you can omit and you'll get an HTML-formatted response).

RK_10062375
5-Regular Member
(To:AC_9552412)

Hi @AC_9552412 

If the provided responses answered your question, please mark as Accepted Solution, for the benefit of others who may have the same question.

 

Regards.

Roshan

nmutter
14-Alexandrite
(To:AC_9552412)

Can you give more details? Maybe postman call, some sample xml which produces the issue or something?

 

You can also have a look how the browser sends the call if you execute it - e.g.:

nmutter_1-1688411268229.png

(but you need to use appKey-header or basicAuth authentication in your postman call)

 

I did notice some strange behavior when the parameter only consists of one tag - it will only show its content. E.g.

nmutter_2-1688411465917.png

 

 

Announcements

Top Tags