We are looking at automating the setup of our Thingworx server. The issue we are running into is in trying to import the extensions, entities, and data programmatically. I can see that ThingWorx is using /Thingworx/DataImporter, /Thingworx/ExtensionPackageUploader, and /Thingworx/Importer to accomplish these tasks when a user does it via the composer. Can I make a JSON request to accomplish the same thing, and if so what parameters are required for these three functions?
I believe you have to Post a file, not sure if it will work for the Extension packages, it will work for the Entities and Data.
You could also perhaps do it with the Import From ThingworxStorage
Another shortcut, if you are deploying on the same version of the Thingworx platform, would be to prepare the ThingworxStorage and BackupStorage folders and deploy with those folders populated. (ie on a machine import everything, turn off Tomcat, copy Storage folders to your deployment)
As Pai said, you can invoke these services programmatically.
Below works for me:
# Import an extension
curl "http://$host/Thingworx/ExtensionPackageUploader?purpose=import&appKey=$APPKEY_ADMIN" -H "X-XSRF-TOKEN: TWX-XSRF-TOKEN-VALUE" -F "file=@Widgets/MyWidget/MyWidget.zip"
# Import Entities (Mashups, Things etc..)
curl "http://$host/Thingworx/Importer?purpose=import&appKey=$APPKEY_ADMIN" -H "X-XSRF-TOKEN: TWX-XSRF-TOKEN-VALUE" -F "file=@Entities_UI.xml"
# Import data
curl "http://$host/Thingworx/DataImporter?purpose=import&appKey=$APPKEY_ADMIN" -H "X-XSRF-TOKEN: TWX-XSRF-TOKEN-VALUE" -F "file=@Sample_Database.json"
I am trying to automate the import extension
I am using the following
curl "http://127.0.0.1:8080/Thingworx/ExtensionPackageUploader?purpose=import&appKey=309bdb66-ee46-4e66-82..." -F "file=@BMS_Quality_ThingWorx_Extension.zip"
curl --user Administrator:Admin http://127.0.0.1:8080/Thingworx/ExtensionPackageUploader?purpose=import" -F "file=@BMS_Quality_ThingWorx_Extension.zip"
I am getting Http Status 500, internal server error
what could be the problem?
the header should contain X-XSRF-TOKEN:TWX-XSRF-TOKEN-VALUE
Hi, can i the name and the password to import a file?
I use it to upload the appkey at the first time...
curl -u $username:$password "http://$host/Thingworx/Importer?purpose=import" -H "X-XSRF-TOKEN: TWX-XSRF-TOKEN-VALUE" -F "file=@Entities_UI.xml"
We tried with the below curl request:
curl -v -u $username:$password 'http://localhost:8080/Thingworx/DataImporter?purpose=import' -H 'X-XSRF-TOKEN: TWX-XSRF-TOKEN-VALUE' -F "file=/path/to/file/04_timeSelection.json"
> POST /Thingworx/DataImporter?purpose=import HTTP/1.1
> Authorization: Basic QWRtaW5pc3RyYXRvcjphZG1pbg==
> User-Agent: curl/7.35.0
> Host: localhost:8080
> Accept: */*
> X-XSRF-TOKEN: TWX-XSRF-TOKEN-VALUE
> Content-Length: 173
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------2ef51ea829890979
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=68899B9E4542AA0A6EB9AE0A3CA564BC; Path=/Thingworx/; HttpOnly
< Expires: 0
< Cache-Control: no-store, no-cache
< Cache-Control: post-check=0, pre-check=0
< Pragma: no-cache
< Transfer-Encoding: chunked
< Date: Wed, 15 Jun 2016 18:48:33 GMT
* Connection #0 to host localhost left intact
Response looks good with 200 OK. But when we checked by logging in to the GUI, we couldn't see that file uploaded to the server.
Please let us know what am I missing.
Hi Dushyant, we have the exact same issue with the 200 OK, how did you fix this?
Hello, did you try to add "@" before the name of the file ?
That works!!! Thank you!