3 Replies Latest reply on May 16, 2017 11:04 AM by petery

    Internal Server Error when updating Person(PUT)

    dmashiku@ncarb.org

      Hi,

       

      I am using the Jive api to update a few properties for users in our Jive community.

      I am using this documentation https://developers.jivesoftware.com/api/v3/cloud/rest/PersonService.html#updatePerson(String, PersonEntity)  to update a user's name and email.

      I am getting the 500 Internal Server Error when I send a PUT request using c#. I use GitHub - jivesoftware/JiveDotNetSDK: .Net SDK for working with Jive.

      After not much luck, I used an example from the Jive community REST API v3 .NET Examples  to "Update a person". Not much luck here either.

       

      So far, I have only been able to partially update a user's profile title in Postman from resources here in Jive.

      I had to set the Content-Type: application/json-patch+json and also X-HTTP-Method-Override: PATCH

      Json:

      [
           {
                "op" : "replace",
                "path" : "/jive/profile/Title",
                "value" : "Member Dun"
           }
      ]
      

       

      A bit at a loss for words! Adding a user was straight forward. I am not sure why updating a user is not working. Here is some of the code from the samples:

      /// <summary>
              /// Updates the specified person object with the specified values
              /// </summary>
              /// <param name="person">Object to be updated</param>
              /// <returns>The updated person JSON string</returns>
              public string UpdateUserProfile(Person person)
              {
                  //there are cases where managers are not fully loaded skip them
                  if (person.name.givenName == null)
                      return "Skipped";    
      
      
                  string personJSON = JsonConvert.SerializeObject(person, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore, Formatting = Formatting.Indented });
                  
                  string jivePeopleUrl = JiveCommunityUrl;
                  jivePeopleUrl += "api/core/v3/people/";
                  jivePeopleUrl += person.id;
      
      
                  string response = string.Empty;
                  try
                  {
                      using (WebClient client = new WebClient())
                      {
                          string credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(_credential.UserName + ":" + _credential.Password));
                          client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
                          client.Headers[HttpRequestHeader.Accept] = "application/json";
                          client.Headers[HttpRequestHeader.ContentType] = "application/json";
      
      
                          response = client.UploadString(jivePeopleUrl, "PUT", personJSON);
                      }//end client                   
                  }
                  catch (Exception ex)
                  {
                      return ex.Message;
                  }
      
      
                  return response;
              }//end updateUserProfile
      

       

      I have been spinning wheels for a while. Any help greatly appreciated.

       

      Thanks.

      Dun

        • Re: Internal Server Error when updating Person(PUT)
          jgoldhammer

          I would try to investigate the response message and/or the jive server logs. If you are on Jive Cloud, you can use Jive Cloud Admin Console to do that.

          Normally, you have to load the user by getPerson, modify some properties you wish to update and save back by using your method.

           

          Thanks

          Jens

            • Re: Internal Server Error when updating Person(PUT)
              dmashiku@ncarb.org

              Hi Jens,

               

              GetPerson() then updating the fields has been my approach. It did not seem to help. I look forward to seeing what you find in the server logs. Thank you again for looking into this.

               

              Thanks,

              Dun

                • Re: Internal Server Error when updating Person(PUT)
                  petery

                  I was not able to update using JsonConvert.SerializeObject(person) last year.

                   

                  Using GetPerson for JSON, if I pass the exact JSON back the update is fine.

                   

                  If I load it into JObject then JObject.ToString(Newtonsoft.Json.Formatting.None)  I get 500 on 8.0.3 Hosted.

                   

                  It worked after I removed these read-only fields:

                   

                              rss.Remove("resources");

                              rss.Remove("updated");

                              rss.Remove("directReportCount");

                              rss.Remove("displayName");

                              rss.Remove("followerCount");

                              rss.Remove("followingCount");

                              rss.Remove("id");

                              rss.Remove("mentionName");

                              rss.Remove("photos");

                              rss.Remove("published");

                              rss.Remove("thumbnailId");

                              rss.Remove("thumbnailUrl");

                              rss.Remove("type");

                              rss.Remove("lastProfileUpdate");

                              rss.Remove("lastAuthenticated");

                              rss.Remove("initialLogin");

                              rss.Remove("tags");

                   

                              JObject rssName = (JObject)rss["name"];

                              rssName.Property("formatted")?.Remove();

                   

                              JObject rssJive = (JObject)rss["jive"];

                              rssJive.Property("enabled")?.Remove();

                              rssJive.Property("external")?.Remove();

                              rssJive.Property("externalIdentities")?.Remove();

                              rssJive.Property("lastProfileUpdate")?.Remove();

                              rssJive.Property("lastAuthenticated")?.Remove();

                              rssJive.Property("locale")?.Remove();

                              rssJive.Property("externalContributor")?.Remove();

                              rssJive.Property("sendable")?.Remove();

                              rssJive.Property("visible")?.Remove();