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

    error 401 depends on API Key settings

    Scheduled Pinned Locked Moved
    Comments & Feedback
    api authorization settings
    2
    3
    4.5k
    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.
    • M
      muravyov.alexey
      last edited by

      Hi.
      I have installed fusionauth on docker and I have written webhook that use FA API to update user data object.
      I use default tenant and have created new application.
      I have created new API Key and select /api/user for GET and PATCH that I use.
      In this case I get error 401
      But if I do not select endpoints (a super user key) then update is successfull.

      FA version [1.31.0]

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

        Hiya,

        Can you share your code that makes the update? Can you try allowing all the HTTP methods for the key on the /api/user endpoint, not just GET and PATCH?

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

        1 Reply Last reply Reply Quote 0
        • M
          muravyov.alexey
          last edited by muravyov.alexey

          I tried with all HTTP methods enabled for /api/user only, and it update user successfully.
          But if I tried only with GET and PATCH methods enabled for /api/user , I get 'statusCode=401'.
          Here is code

          import { FusionAuthClient, UserRequest } from '@fusionauth/typescript-client'
          ...
          export class FusionAuthService {
              private fusionAuthClient: FusionAuthClient;
          
              constructor(private context: Context) {
                  this.fusionAuthClient = new FusionAuthClient(context.config.fusionAuth.apiKey, context.config.fusionAuth.apiUrl);
              }
          
          ...
              public async updateUser(userId: string, userRequest: UserRequest ) {
                  return this.fusionAuthClient.updateUser(userId, userRequest)
                      .then(clientResponse => {
                          logger.info("User:", JSON.stringify(clientResponse.response.user, null, 2));
                      }).catch(logger.error);
              }
          

          here is invocation of updateUser method that happens on 'user.registration.create' event

                  if (user) {
                      const patchBody = {
                          user: {
                              email: event.user.email,
                              data: {
                                  userId: user.id
                              }
                          },
                      }
                      await this.fusionAuthService.updateUser(event.user.id, patchBody);
                  }
          
          

          Now I understand that I use updateUser method and I don't know what kind of HTTP request it used.
          I have found patchUser and with it get success.

          Thanks for your help.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post