Skip to main content
1-Visitor
October 3, 2017
Question

how to access parameters using REST API (post method)

  • October 3, 2017
  • 1 reply
  • 3857 views

Hello

I have to connect a service provider API  to a Thingworx service using REST POST ( with some parameters into the header and a json structure into the body)

In order to understand and debug first,  I'm using POSTMAN to reproduce the API from provider.

I have created the Thingworx service and I am well accessing to it from postman using an appKey as header parameter.

the result of the service ("OK") is well returned to postman


I have followed some forum topics which are describing this,  but I'm not able to access to the other parameters and to the json structure into the javascript code of the Thingworx service.

Should I have to define one input parameter for each header parameter with the same name ? what should be the name of the json structure into the body ?

each time I try to display an input parameter into the logger I get "undefined"

thanks for help

Pascal

1 reply

pjoly1-VisitorAuthor
1-Visitor
October 3, 2017

UPDATE

I managed to get the parameters in the header (problem with Postman ?) but I'm still looking how to retrieve a json structure into the body

Thnaks

5-Regular Member
October 7, 2017

Hey Pascal,

If I understand correctly, you are trying to post a JSON body parameter to a Thingworx service via REST.

The correct way to do this is using the postParameter url parameter when invoking the service; here is an example:

Create a service with the parameter name json

add the URL Parameter postParameter where the value is the name of the json parameter you wish to pass:

Here is a cURL example:

curl -X POST \

  'http://localhost/Thingworx/Things/Main.FileRepository/Services/TestService?postParameter=json' \

  -H 'accept: application/json' \

  -H 'appkey: efdb7b81-461c-4d04-bffb-a4e0fd2cd85c' \

  -H 'cache-control: no-cache' \

  -H 'content-type: application/json' \

  -H 'postman-token: c03973a6-a9ff-9786-1f88-47e757612c75' \

  -d '{"test": 10}

'

pjoly1-VisitorAuthor
1-Visitor
October 7, 2017

thanks it is clear