Skip to main content
13-Aquamarine
January 7, 2023
Solved

Issue in creating Thing using RESTAPI

  • January 7, 2023
  • 1 reply
  • 9363 views

Hello Team,

 

Greeting of the day!

I'm trying to connect to the ThingWorx platform and make REST calls to call Services, update Properties, to make calls to REST API I m using POSTMAN. It's throwing me 400 error.

 

I', attaching all my details here.

 

http://localhost:8080/Thingworx/Resources/EntityServices/Services/CreateThing

Used the app key 

Accept: application/json

content type: application/json

 

{
 "name": "SomeTestThing",
 "thingTemplateName": "GenericThing"
}

 

Kindly help me to resolve this.

 

Thanks in advance.

 

AS

Best answer by nmutter

To make it easier: Can you share your postman request? You need to add it to a postman collection. On the collection you can rightclick and export to a .json file. So we can import your request and see what is wrong.

1 reply

17-Peridot
January 9, 2023

It all looks correct.

Just to double-check, you're setting appKey, Content-Type and Accept in the headers and the json is in the body, right?

Are you using a custom developed app to send the request or doing it via Postman or plain curl?

I'd suggest to try first with Postman if you haven't yet.

 

There are a few TS articles / cases, e.g. https://www.ptc.com/en/support/article/cs341975 (issue related to  .Net SDK version) and https://www.ptc.com/en/support/article/cs343724 (issue related to incorrectly set headers)

I'd also check the logs to see the full 400 error response - additional details there can help.

 

Also it can be just a matter of a typo - I've attached a screenshot (0012.png) with http 400 error and the cause is just an extra comma.

I've also attached the screenshots (0011.png and 0011a.png) with correct headers and body sections, just for reference.

There are extra fields in the json body - description and tags, they're optional, having name and thingTemplateName is enough.

AS_130713-AquamarineAuthor
13-Aquamarine
January 9, 2023

Hello,

 

Thanks for the response. I'm using  POSTMAN to send request. I've tried as per your guidance and attaching the same, but still i'm facing 400 error.

 

Please have a look.

17-Peridot
January 9, 2023

What's in the response body and what's the full status of the 400 error?

On the screenshot below I intentionally added extra comma to reproduce the 400 error to show where you can check it.

There also can be extra details in the `ApplicationLog.log` and `ErrorLog.log` in the `Thingworx Storage\logs` folder

 

DmitryTsarev_1-1673257077922.png

DmitryTsarev_2-1673257353751.png