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

Request POST

Highlighted
Participant

Request POST

Hi, i'm trying to do a POST request in Thingworx. Trying to connect to netatmo. I created a new service on a thing and searched trough snippets i founded the postJSON one.

Doing it trough ajax like this return me a correct JSON object:


$.ajax({

        type: "POST",

        accept:"application/x-www-form-urlencoded;charset=UTF-8",

        contentType:"application/x-www-form-urlencoded;charset=UTF-8"   ,

        dataType:"json",

        data:{grant_type:"mYString",

            client_id:"MStringID",

            client_secret:"MyStringSecret",

            username:"MyUser",

            password:"MyPassword",

        },

        success: function (data) {console.log(data)}

})


doing it with thingworx i receive from the server i'm trying to connect "invalid request" string. So the POST is correctly Done but the content is not what i'm expecting. I think headers or other param are not set good. Can anyone help me please ?

is this snippet equal to what i wrote in my ajax request ?



var params = {

    headers: {accept:"application/x-www-form-urlencoded;charset=UTF-8",

              contentType:"application/x-www-form-urlencoded;charset=UTF-8"

              

    } /* JSON /,</div><div>    //dataType:"json",</div><div><span class="Apple-tab-span" style="white-space:pre">     </span></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>url: "http://api.netatmo.net/oauth2/token" / STRING /,</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>ignoreSSLErrors: true / BOOLEAN /,</div><div>    content: {<span class="Apple-tab-span" style="white-space:pre">     </span>grant_type:"password",</div><div>            <span class="Apple-tab-span" style="white-space:pre">     </span>client_id:"MyId",</div><div>            <span class="Apple-tab-span" style="white-space:pre">     </span>client_secret:"MySec",</div><div>            <span class="Apple-tab-span" style="white-space:pre">     </span>username:"MyUser",</div><div>              <span class="Apple-tab-span" style="white-space:pre">     </span>password:"MyPsw"} / JSON */,

    domain:undefined

}

// result: JSON

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


Thanks






1 REPLY 1
Highlighted

Re: Request POST

Little up for this question, did you have some problem doing post request from snippet ? I mean issue about CORS request on Tomcat ?

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!