cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

format of JSON for PUT method of geo type property

Re: format of JSON for PUT method of geo type property

Hi,

What I mean is just change your param Type from JSON to String. Then you can use Event to pars it to the JSON by using JSON.parse(yourStringVal) to have a JSON.

I am not saying that it will work, but I had similar problem with Service and JSON input so it can be the same issue.

Regards,

Adam

Re: format of JSON for PUT method of geo type property

Thanks for Quick Reply,

My requirement is some little bit different, I need to write the script code where it will take the current property values and that values need to post to REST API in a specific format of a json.

I am getting confusing how should and where to  include that json format in the script code.

Re: format of JSON for PUT method of geo type property

I tested your values and I am receiving 406. Probably because "elevation": "033333" is not acceptable.

This is my JSON:

{

    "location": {

        "latitude": 0.1111,

        "longitude": 0.2222,

        "elevation": 0.3333,

        "units": "WGS84"

    }

}

Remember also to setup proper REST Headers:

appKey/Authorization

Accept -> application/json

ContentType -> application/json.

You also check for ThingWorx logs to see if there is more information there.

Regards,

Adam

Hi  just I want to try like the above code Could you please help me out

Re: format of JSON for PUT method of geo type property

Now I am also confused. Can you described whole workflow one more time? Where is the input, what should be the output?

Thanks,

Adam

Re: format of JSON for PUT method of geo type property

Ok. What you need to know is that I used 3rd party application to send this REST PUT call. You want to send this REST inside ThingWorx in Service? What is your goal?

Re: format of JSON for PUT method of geo type property

{

  "jsonData": {

    "ConnectionID": "F-105",

    "current": 320.77,

    "voltage": 640,

    "KW": 480.23,

    "Powerfactor": 80.85,

    "timestamp": 1511793691000

  }

}

this is the format of json my REST API will accept in payload or body area. the key values of json should be take from the property values of the thing. I need to code that in script area so that it will take the values from the current values of the property and the format of json should look like this should be posted to my REST API URL. output should show status of 200 ok thats it.

Re: format of JSON for PUT method of geo type property

yes exactly I dont want to use any third party application .

Re: format of JSON for PUT method of geo type property

var jsomData = {

  "jsonData": {

    "ConnectionID": me.connectionID,

    "current": 320.77,

    "voltage": 640,

    "KW": 480.23,

    "Powerfactor": 80.85,

    "timestamp": 1511793691000

  }

};

var params = {

proxyScheme: undefined /* STRING */,

headers: undefined /* JSON */,

ignoreSSLErrors: undefined /* BOOLEAN */,

useNTLM: undefined /* BOOLEAN */,

workstation: undefined /* STRING */,

useProxy: undefined /* BOOLEAN */,

withCookies: undefined /* BOOLEAN */,

proxyHost: undefined /* STRING */,

url: undefined /* STRING */,

content: jsonData /* JSON */,

timeout: undefined /* NUMBER */,

proxyPort: undefined /* INTEGER */,

password: undefined /* STRING */,

domain: undefined /* STRING */,

username: undefined /* STRING */

};

// result: JSON

var result = Resources["ContentLoaderFunctions"].PutJSON(params);

You can try with PutJSON method under Resources -> ContentLoaderFunctions.

Instead of hardcoded values you can refer to your property value like under the ConnectionID.

Re: format of JSON for PUT method of geo type property

Thanks Adam,

I will try this code.

Re: format of JSON for PUT method of geo type property

Thanks Adam that code is working fine and posting successfully.