5 Replies Latest reply on Mar 30, 2015 8:56 AM by thales

    How to update attribute value in GET JSON response

    thales

      I am using Python and the Rest API (/api/core/v3/people/{personID}) to update a user account to deactivated (jive.enabled = False). I tried updating the enabled attribute, but I am getting a 400 (Bad Request) response. I believe this may be because I need to pass all of the attributes into the PUT request from the GET request. My problem is that I am not finding an easy way to just update the enabled attribute without having to rewrite the whole JSON response. Is there a way to do this? Thanks!

        • Re: How to update attribute value in GET JSON response
          mattdickens

          I think there is a minimum set of values you need to include in the JSON. i think its id, name,email and if the account is federated, make sure you send that too otherwise it defaults to false (bug that did exist in 7.01 anyway).

          I think you'll have to perform a call to the person api via id or email with &fields=[above fields], -resources, grab the returned JSON and send it back with the enabled=false entry added.

           

          This very script is on my todo list and ill either do it like the above OR if i'm given a spreadsheet of members to remove that has all fields i require, i can build up the minimum JSON along with the enabled= false entry and have some JS in a  HTML widget just loop through a table that has been copied/pasted into a formatted text widget on the same group overview page.

          1 person found this helpful
            • Re: How to update attribute value in GET JSON response
              thales

              Well that has gotten me a little closer, but now I get a 500 Internal Server Error. Here is part of my code.

               

              pApi = "/api/core/v3/people/username/{}".format(p)
              urlUsername = base_url + pApi
              reqUsername = requests.get(urlUsername, headers=headers )
              data = reqUsername.content
              
              
              #Remove security header
              data2 = data.replace("throw 'allowIllegalResourceCall is false.';", "")
              jsonData = json.loads(data2)
              #print jsonData
              pId = jsonData["id"]
              pUsername = jsonData["jive"]["username"]
              iLogin = jsonData["initialLogin"]
              lAuth = jsonData["jive"]["lastAuthenticated"]
              uName = jsonData["name"]
              uEmail = jsonData["emails"]
              uFederated = jsonData["jive"]["federated"]
              
              #print jsonData
              
              data = json.dumps(
                   {"name" : uName,
                    "emails" : uEmail,
                    "id" : pId,
                    "jive" : {
                      "enabled" : "False",
                      "federated" : uFederated},
                    })
              
              pApi2 = "/api/core/v3/people/{}".format(pId)
              urlId = base_url + pApi2
              
              try:
                  reqUsername = requests.put(urlId, data=data, headers=headers )
                  data = reqUsername.content
                  print reqUsername.status_code
                  print reqUsername.reason