• Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login
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
935
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 27 Oct 2022, 11:37

    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

    D 1 Reply Last reply 29 Oct 2022, 13:20 Reply Quote 0
    • D
      duke @dan
      last edited by duke 11 Jan 2022, 14:30 1 Nov 2022, 09:59

      @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()
          }];
      
      D A 2 Replies Last reply 1 Nov 2022, 13:49 Reply Quote 1
      • D
        dan @duke
        last edited by 29 Oct 2022, 13:20

        @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 1 Nov 2022, 09:59 Reply Quote 0
        • D
          duke @dan
          last edited by duke 11 Jan 2022, 14:30 1 Nov 2022, 09:59

          @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()
              }];
          
          D A 2 Replies Last reply 1 Nov 2022, 13:49 Reply Quote 1
          • D
            dan @duke
            last edited by 1 Nov 2022, 13:49

            @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 3 Nov 2022, 09:28

              @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 8 Nov 2022, 12:35
              4 out of 5
              • First post
                4/5
                Last post