Add a Mashup to Thingworx via REST
Why would you do this?
You can use REST to generate and update mashups based on data once you understand the data structure and vocabulary of mashups and widgets.
You will need access to a Thingworx Instance. You can find hosted trial instances on PTC’s Thingworx learning site.
- Create an empty Mashup, save it and immediately close it.
- Re-open the Mashup, click the Design button and add a simple widget such as button.
- Clear the network tab history
- Click Save
- Find the request URL (usually it will be the top entry on the XHR list) and scroll down to request payload on the Right of the network history.
- Click view source link and Show more link at bottom of source view at the bottom of source text if it appears.
- Copy the whole thing.
Use browser Dev tools Network tab to get the header and body of a request to save an existing Mashup.
Use Postman to create a PUT request. Here is an example request URL: http://localhost:8080/Thingworx/Mashups/MashupName?reason=Mashup%20%3A%20design%20%3A%20updated%0A
You don’t need any other Query Params. Header key/value pairs that might need to be set:
X-Content-Type-Options: nosniff
X-XSS-Protection: 1;mode=block
Content-Security-Policy: frame-ancestors 'self'
X-Frame-Options: SAMEORIGIN
Content-Type: text/html;charset=UTF-8
You can use basic Auth, but you will need to set the PlatformSubsystem configuration Allow Request Method Switch to true to allow REST calls with it. This is more convenient than setting up application keys, but not for production due to security concerns
Click the Body tab in Postman, click raw radio button, and then Paste the request body that was copied from the network tab source view.
Send the new request.
![Thingworx Logo](https://i0.wp.com/davidjmcclelland.com/wp-content/uploads/2020/01/thingworxBug.jpg?resize=64%2C64&ssl=1)