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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

How to send JSON and receive binary via http post

JayT9000
10-Marble

How to send JSON and receive binary via http post

Hi everyone,
is there a way in thingworx to make a http post request with JSON or text content to an external service and receive a BLOB?

 

 

 

// result: JSON
var result = Resources["ContentLoaderFunctions"].PostJSON({
url: "http://xyz:8080/createFile",
content: {"filename":"test"}
});

Things["MyRepository"].SaveBinary({
    path: "/",
    content: result 
});

 

 

 

The PostJSON method expects a JSON response but we would like to store the received binary in a file repository.

 

Is there a more generic way to make HTTP requests or do we have to create a extension for that.

Thanks

ACCEPTED SOLUTION

Accepted Solutions

Hi eyeryone,
a look into the source code offers us that it's not possible with the out of the box services provided by Thingworx. We had to create an extension for that.

 

Best regards

View solution in original post

4 REPLIES 4
slangley
23-Emerald II
(To:JayT9000)

Hi @JayT9000.

 

Without knowing more regarding your use case, it sounds like the information is being returned as JSON.  Therefore, you would need to parse it for the desired information.

 

If we're failing to understand your request, please provide details of your use case and we'll take another shot at it.

 

Regards.

 

--Sharon

Hi Sharon,
Thanks for your reply. We have an external service which generates a binary file and we would like to store it in a file repository in thingworx. It seems that all http requests of the ContentLoaderFunctions resources expects the same output like the input.
e.g.
PostJSON -> send JSON --> expect JSON as result
PostBinary -> send BLOB --> expect BLOB as result

But in our case the service needs to receive JSON via post and sends a blob back.
Do you have any ideas?

Best regards
Jan

slangley
23-Emerald II
(To:JayT9000)

Hi @JayT9000.

 

We're still not clear on your use case.  You indicated your external service is creating a binary file, but then state that the service needs to receive JSON.  What is this external service that is generating the binary file?  If you want it stored in the ThingWorx repository as JSON, you will either need to convert it before sending to ThingWorx or write a service in ThingWorx to handle the conversion.  The snippets provided in ThingWorx may require some additional coding to function as needed.

 

Regards.

 

--Sharon

Hi eyeryone,
a look into the source code offers us that it's not possible with the out of the box services provided by Thingworx. We had to create an extension for that.

 

Best regards

Announcements


Top Tags