4 Replies Latest reply on Sep 26, 2017 10:47 AM by jgonçalves RSS
    jgonçalves Explorer

    Set User Extensions' properties via REST-API

    I it possible to set new values for the User Extensions' properties of a specific user via REST-API?

    We've tried invoking the SetProperties and we would get 200 OK response, but the property we were trying to update would not be updated.

     

    Thank you.

      • Re: Set User Extensions' properties via REST-API
        jbester Explorer

        Good day João,

         

        I was able to set the property "firstName" using a PUT request as follows:

         

        http://<Server>/Thingworx/Users/<User>/Properties/firstName

         

        The headers (appKey, Content-Type)

        The body: {"firstName" : "test"}

         

        You can change the property name to the property you want to update.

         

        In theory, you should be able to use the SetPropertyValues service with a POST request but it seems like the input to the service is an infotable and I am not sure how the body structure of the REST call will look then.

         

        I hope this helps somewhat.

         

        Kind regards,

        Johan Bester        

          • Re: Set User Extensions' properties via REST-API
            jgonçalves Explorer

            Hello Johan!

             

            I've tried what you suggested, yet it didn't work... I received a 404 Bad Request.

             

            So I tried using SetPropertyValues and building the InfoTable. That did the :

             

            URL: https://<MY_TWX_SERVER>/Thingworx/Users/<MY_USER>/Services/SetPropertyValues

            BODY:

            {

               "values":{ 

                  "created":1506422819087,

                  "description":"",

                  "name":"Infotable",

                  "dataShape":{

                     "fieldDefinitions":{

                        "<PROPERTY_NAME>":{

                           "name":"<PROPERTY_NAME>",

                           "aspects":{

                              "isPrimaryKey":true

                           },

                           "description":"",

                           "baseType":"STRING",

                           "ordinal":0

                        }

                     },

                     "name":"EntityList",

                     "description":"Entity list"

                  },

                  "rows":[

                     {

                        "<PROPERTY_NAME>":"<PROPERTY_NEW_VAUE"

                     }

                  ]

               }

            }

              • Re: Set User Extensions' properties via REST-API
                jbester Explorer

                Thank you for the feedback João, now I know for future reference.

                 

                It is strange that my suggested method didn't work, I did test it again to make sure it works (are you sure you set it to a PUT call?), did you change the property you want to update in the URL as well as the body? otherwise it might be permissions issues if the appKey you used isn't an administrator.

                 

                But I guess it doesn't really matter since you were able to do what you needed to do.

                 

                I am glad if my input helped.

                (If you could mark an answer as correct to change the question's classification from "Not answered" to answered, it might help future people looking for answered questions)

                  • Re: Set User Extensions' properties via REST-API
                    jgonçalves Explorer

                    Johan Bester escreveu:

                     

                    Thank you for the feedback João, now I know for future reference.

                     

                    It is strange that my suggested method didn't work, I did test it again to make sure it works (are you sure you set it to a PUT call?), did you change the property you want to update in the URL as well as the body? otherwise it might be permissions issues if the appKey you used isn't an administrator.

                     

                    But I guess it doesn't really matter since you were able to do what you needed to do.

                     

                    I am glad if my input helped.

                    (If you could mark an answer as correct to change the question's classification from "Not answered" to answered, it might help future people looking for answered questions)

                    I was using POST, as soon as I've tried PUT it worked as you suggested, with a much friendlier JSON body.

                     

                     

                    Thank you for your fast and accurate response