FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    UpdatinG User with JSON-PATCH method

    Scheduled Pinned Locked Moved Solved
    Q&A
    3
    5
    924
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      duke
      last edited by duke

      Hey, we are using User API to update user PerferredLanguage. Currently we have two languages and we want to change email template based on that user language.

      We want to have just one language at any given time so want to update the User PerferredLanguage using Json-patch method.

      User{
       PerferredLanguage: [ "English"]
      }
      

      when using json-patch https://fusionauth.io/docs/v1/tech/apis/#the-patch-http-method it seems like am not getting the path right. Looking at the example provide i cant why the request body from the example become

      [
        {
          "op": "remove",
          "path": "/roleIds/1"
        }
      ]
      

      How do we resolve to the path to become "path": "/roleIds/1" ?
      or in my case, how would the body be ?

      Thanks

      danD 1 Reply Last reply Reply Quote 0
      • D
        duke @dan
        last edited by duke

        @dan It was abit confusing because looking at the original body of the group, there was no parameter/ field called roleIds but it was used in the request.

        To update the User we used this.

        // To remove language
         let body = vec![Testing {
                op: "remove".to_string(),
                path: "/user/preferredLanguages/0".to_string()
            }];
        
        danD A 2 Replies Last reply Reply Quote 1
        • danD
          dan @duke
          last edited by

          @duke

          Hiya,

          I would have to play around with this for a while, but we've found this online tool to be useful when trying to figure out how to take one JSON document and transform it to another:

          https://json-patch-builder-online.github.io/

          Dan

          --
          FusionAuth - Auth for devs, built by devs.
          https://fusionauth.io

          D 1 Reply Last reply Reply Quote 0
          • D
            duke @dan
            last edited by duke

            @dan It was abit confusing because looking at the original body of the group, there was no parameter/ field called roleIds but it was used in the request.

            To update the User we used this.

            // To remove language
             let body = vec![Testing {
                    op: "remove".to_string(),
                    path: "/user/preferredLanguages/0".to_string()
                }];
            
            danD A 2 Replies Last reply Reply Quote 1
            • danD
              dan @duke
              last edited by

              @duke

              Sounds good, thanks for sharing.

              I think groups were one of the first APIs and so have some quirks. Glad you figured it out.

              --
              FusionAuth - Auth for devs, built by devs.
              https://fusionauth.io

              1 Reply Last reply Reply Quote 1
              • A
                alexsunny734 @duke
                last edited by

                @duke said in UpdatinG User with JSON-PATCH method:

                @dan It was abit confusing because looking at the original body of the group, there was no parameter/ field called roleIds but it was used in the request.

                To update the User we used this.

                // To remove language
                 let body = vec![Testing {
                        op: "remove".to_string(),
                        path: "/user/preferredLanguages/0".to_string()
                    }];
                

                thanks my issue has been fixed.

                1 Reply Last reply Reply Quote 0
                • D duke has marked this topic as solved on
                • First post
                  Last post