4 Replies Latest reply on Oct 26, 2016 10:34 AM by ttielebein RSS
    gbeaumont Explorer

    [POSTJson] model POSTJson

    Hi guys !

     

    I'm trying to join an extern API with Thingworx. I format my request with POSTMAN and now I want to use the snippet service PostJSON.

     

    But I always had syntax issues with it.

     

    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: "https://api.netatmo.com/oauth2/token" /* STRING */,

      content: {

    "grant_type":"password"

    "client_id":"[YOUR_CLIENT_ID]"

    "client_secret":"[YOUR_CLIENT_SECRET]"

    "username":"[USERNAME]"

    "password":"[PASSWORD]"

     

    "/* JSON */,

      timeout: undefined /* NUMBER */,

      proxyPort: undefined /* INTEGER */,

      password: undefined /* STRING */,

      domain: undefined /* STRING */,

      username: undefined /* STRING */

    };

     

     

    // result: JSON

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

     

    Can you help me about how correctly use the syntax ?

     

    Regards,

     

    Guillaume

      • Re: [POSTJson] model POSTJson
        pchung Collaborator

        "/* JSON */,

          timeout: undefined /* NUMBER */,

          proxyPort: undefined /* INTEGER */,

          password: undefined /* STRING */,

          domain: undefined /* STRING */,

          username: undefined /* STRING */

        };

         

        seems to have " but no closing one, these items also seem placed rather strange.

          • Re: [POSTJson] model POSTJson
            gbeaumont Explorer

            Finally, I changed my code for :

             

            var contents={

                'Content-Type': 'multipart/form-data',

                'grant_type':'password',

                'client_id':'[YOUR_CLIENT_ID]',

                'client_secret':'[YOUR_CLIENT_SECRET]',

                'username':'[USERNAME]',

                'password':'[PASSWORD]'

            };

               

               

               

            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: 'https://api.netatmo.com/oauth2/token' /* STRING */,

              content: contents /* JSON */,

              timeout: undefined /* NUMBER */,

              proxyPort: undefined /* INTEGER */,

              password: undefined /* STRING */,

              domain: undefined /* STRING */,

              username: undefined /* STRING */

            };

             

             

            // result: JSON

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

            var result = JSON.stringify(resultJson);

             

             

             

            No more errors but when I test my service in TW the result is {"headers":"","error":"invalid_request"}

            I don't understand why