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

Upload .CSV file to Thingworx via REST API

SOLVED
Highlighted
Contributor

Upload .CSV file to Thingworx via REST API

Hello,

 

I´m trying to upload a .CSV to Thingworx. I achieved it creating a service with CSV Parser, code:


var params = {
path: "/Tabla1.csv" /* STRING */,
columnMappings: "Temperature;Humidity;DateTime" /* STRING */,
hasHeader: true /* BOOLEAN */,
longitudeField: undefined /* NUMBER */,
dateFormat: "dd-mm-yy HH:mm:ss.sss" /* STRING */,
fileRepository: "DataLogger_1_Repository" /* THINGNAME */,
latitudeField: undefined /* NUMBER */,
fieldDelimiter: ";" /* STRING */,
stringDelimiter: "/" /* STRING */,
dataShape: "DataLogger_Shape" /* DATASHAPENAME */
};

// result: INFOTABLE
var result = Resources["CSVParserFunctions"].ReadCSVFile(params);

 

But now, I want send .CSV via REST API for instance with POSTMAN. I don´t know how I can do this. I put the URL (localhost:8080/Thingworx/Things/DataLogger_1_Repository/Services/), auth and headers but the body...

Could you help me with that?

 

Thank you in advance

BR

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Upload .CSV file to Thingworx via REST API

Hi @ljam.

 

This article from our Knowledge Base may offer some assistance.

 

Regards.

 

--Sharon

 

 

View solution in original post

3 REPLIES 3

Re: Upload .CSV file to Thingworx via REST API

Hi @ljam.

 

This article from our Knowledge Base may offer some assistance.

 

Regards.

 

--Sharon

 

 

View solution in original post

Re: Upload .CSV file to Thingworx via REST API

Hi Sharon,

 

Yes very helpfull, I saw that article and I solved it.

First I create a service with JSON input, INFOTABLE output and this code:

 

var par = {
path: params.path/* STRING */,
columnMappings: params.columnMappings /* STRING */,
hasHeader: params.hasHeader /* BOOLEAN */,
longitudeField: params.longitudeField /* NUMBER */,
dateFormat: params.dateFormat /* STRING */,
fileRepository: params.fileRepository /* THINGNAME */,
latitudeField: params.latitudeField /* NUMBER */,
fieldDelimiter: params.fieldDelimiter /* STRING */,
stringDelimiter: params.StringDelimiter /* STRING */,
dataShape: params.dataShape /* DATASHAPENAME */
};

// result: INFOTABLE
var result= Resources["CSVParserFunctions"].ReadCSVFile(par);

me.Result= result;

 

Later I program a python code to send .CSV via REST API

 

while True:
DATA={
"params":
{
"path" : "/Tabla1.csv",
"columnMappings" : "Temperature;Humidity;DateTime",
"hasHeader" : 'true',
"longitudeField" : 1,
"dateFormat" : "dd-MM-yy HH:mm:ss.SSS",
"fileRepository" : "DataLogger_1_Repository",
"latitudeField" : 1,
"fieldDelimiter" : ";",
"stringDelimitir" : "/",
"dataShape" : "DataLogger_Shape"
}
}

r2=requests.post(url=URL, auth=AUTH, headers=HEADERS, json=DATA)

 

Thank you Sharon,

BR

Re: Upload .CSV file to Thingworx via REST API

Hi @ljam.

 

If you feel your question has been answered, please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon