Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi,
I am trying to explore the Thingworx Analytics API - 8.1. I was trying to use the GetDatasetSchema service on the localhost-AnalyticsServer_DataThing as a REST API. Although there is API guide at ThingWorx Analytics API , an example will help me.
Any documents giving example usages for the TWX Analytics API 8.1?
Thanks and Regards,
Jyothi
Solved! Go to Solution.
Hi Jyothi
You may want to have a look at this article: https://www.ptc.com/en/support/article?n=CS271485
There are some explanation and most importantly, as far as example as concerned, you have a json collection file (at the very bottom) that you can download and import into, let's say Postman, to check some examples.
Hope this helps.
Kind regards
Christophe
Hi Jyothi
You may want to have a look at this article: https://www.ptc.com/en/support/article?n=CS271485
There are some explanation and most importantly, as far as example as concerned, you have a json collection file (at the very bottom) that you can download and import into, let's say Postman, to check some examples.
Hope this helps.
Kind regards
Christophe
Hi Christophe,
Thanks you very much for getting back... that really helped!
I am particularly trying to use the API
http://127.0.0.1:8888/ThingWorx/Things/localhost-AnalyticsServer_DataThing/Services/GetDatasetSchema
The documentation at ThingWorx Analytics API mentions the details. I am giving the body as follows, But I am still getting a 404. Any ideas what might be going wrong?
{"dataSource": {
"dataShape": {
"fieldDefinitions": {
"datasetUri": {
"name": "datasetUri",
"description": "Location of the data",
"baseType": "STRING",
"ordinal": 0,
"aspects": {}
},
"format": {
"name": "format",
"description": "Structure of the data (CSV,PARQUET,CLQUET)",
"baseType": "STRING",
"ordinal": 0,
"aspects": {}
},
"filter": {
"name": "filter",
"description": "SQL WHERE clause to refine the dataset",
"baseType": "STRING",
"ordinal": 0,
"aspects": {}
},
"exclusions": {
"name": "exclusions",
"description": "Fields to remove from the dataset",
"baseType": "INFOTABLE",
"ordinal": 0,
"aspects": {
"dataShape": "GenericStringList"
}
},
"data": {
"name": "data",
"description": "An infotable of data (must be flat. for providing data as part of request)",
"baseType": "INFOTABLE",
"ordinal": 0,
"aspects": {}
},
"metadata": {
"name": "metadata",
"description": "Metadata of the dataset (for providing data as part of request)",
"baseType": "INFOTABLE",
"ordinal": 0,
"aspects": {
"dataShape": "AnalyticsDatasetMetadata"
}
}
}
},
"rows": [
{
"datasetUri": "dataset:/1715c6d4-a513-44fa-be49-68fcd1075642",
"format": "parquet"
}
]
}
}
Thanks and Regards,
Jyothi
Hi Jyothi
I have used your code and it works for me.
Since you are gettign a 404 error this woudl indicate that the URI has some error.
Are you sure of the Thing name in the URI ?
Thanks
Christophe
Hi Christophe,
The Thing name is correct. I could execute the ListCreatedDatasets API with this thing. Is there a way to access the http access logs to understand what is the REST URI that reached the server? I can compare mine with the one executed via Thingworx Test Services. The same service executed via ThingWorx works fine.
Thanks and Regards,
Jyothi
Hi Jyothi
You can get the access.log (and error.log) with the command: docker cp nginx:/var/log/nginx .
This will copy the /var/log/nginx folder to the local path, change . with the full path to the local directory if you want it somewhere else.
hope this helps.
Kind regards
Christophe
Hi,
I am now trying to create a Javascript service in my own ThingTemplate which internally calls the GetDataSchema. This is how I am doing it.
var dataSet = Things['localhost-AnalyticsServer_DataThing'].ListCreatedDatasets();
var params = {
infoTableName : "InfoTable",
dataShapeName : "AnalyticsDatasetRef"
};
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(AnalyticsDatasetRef)
var infoTable1 = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
// AnalyticsDatasetRef entry object
var newEntry = new Object();
newEntry.filter = dataSet.filter; // STRING
newEntry.datasetUri = dataSet.datasetUri; // STRING
newEntry.metadata = dataSet.metadata; // INFOTABLE
newEntry.data = dataSet.data; // INFOTABLE
newEntry.format = dataSet.format; // STRING
newEntry.exclusions = dataSet.exclusions; // INFOTABLE
infoTable1.AddRow(newEntry);
logger.debug(infoTable1);
result = Things['localhost-AnalyticsServer_DataThing'].GetDatasetSchema(infoTable1);
But I am getting the error:
Wrapped java.lang.Exception: Invalid parameter type for service : [GetDatasetSchema] on localhost-AnalyticsServer_DataThing Cause: Invalid parameter type for service : [GetDatasetSchema] on localhost-AnalyticsServer_DataThing
Any ideas?
Thanks and Regards,
Jyothi
Got it!
var params = {
dataSource: infoTable1 /* INFOTABLE */
};
// result: INFOTABLE dataShape: AnalyticsDatasetMetadata
result = Things["localhost-AnalyticsServer_DataThing"].GetDatasetSchema(params);