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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Calling a service with a POST Request

claudef
1-Visitor

Calling a service with a POST Request

Hello there,

I'm trying to use the REST API to call services and I can do it in some ways, but not those I want/need

Using POSTMAN on Chrome :

POST /Thingworx/Things/Mail/Services/sendPassword HTTP/1.1

Host: ***.net:8080</span><br style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">appKey: xxxx-xxxx</span><br style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Content-Type: application/json</span><br style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Accept: application/json</span><br style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Cache-Control: no-cache</span><br style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span style="color: rgb(51, 51, 51); font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">{"userid":"claude","usermail":"c@f.com"}</span><br><br>i'm passing a json object as raw data and it get things done<br><br>now i'm trying to do it using jQuery but the service never get the parameters, they're all undefined<br><br>here's my code : <br>$('#passform').submit(function() {<br>    <br>        var jsonReq = '{';<br>        jsonReq += '"usermail": "c@f.com",';<br>        jsonReq += '"userid": "claude"';<br>        jsonReq += '}';<br>                <br>        /
        var jsonReq = new Object();
        jsonReq.userid = 'claude';
        jsonReq.usermail = 'c@f.com';
        /<br>        <br>        var hders = new Object();<br>        hders.appKey = 'xxxx-xxxx';<br>                <br>        console.log(jsonReq);<br>        //console.log(JSON.stringify(jsonReq));<br>        console.log(JSON.parse(jsonReq));<br>                <br>        var options = {<br>            url: 'http://***:8080/Thingworx/Things/Mail/Services/sendPassword',
            async: true,
            success: function(txt, statusText, xhr) {
                alert(txt);
            },
            contentType: 'application/json',
            data: JSON.stringify(jsonReq),
            //data: jsonReq,           
            //processData: false,
            headers: hders
        };
        // submit the form
        $(this).ajaxSubmit(options);
                alert('foo');
        // return false to prevent normal browser submit and page navigation
        return false;
    });

it basically works except the data aint sent the way I want since the service don't get them

I left nothing except for the button in the html form

Thanks


2 REPLIES 2
paic
12-Amethyst
(To:claudef)

If you haven't found your answer to this yet, I would recommend you go to support.ptc.com to log a case.

claudef
1-Visitor
(To:paic)

For future viewers : I think it's just that jQuery changes the data one way or another
I finally did it using Java scriplet in a JSP page



Announcements


Top Tags