Is there a way to update User API fields in Nav Bar Apps?

8 Comments

  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Gaby Bitar,

    If I'm not mistaken, you do not have access to a user object in navbar app. So, you won't have context indicating a specific user. Unless you invoke the navbar app from a location that has access to user object (e.g. ticket sidebar). See Messaging between locations.

    0
  • Gaby Bitar

    Ahmed Zaid Thank you for this, but in the Nav Bar app I am puling all users from the Users API using client.request(). I am able to pull all the users and list them on the app, however, I can't find a way to update any User fields. I would like to do this using a Users ID if possible.

    I want to be able to select a User and update their Role or Suspension status directly from that app.

    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Gaby Bitar In that case you can again use client.request() to update the user end point. Refer to the API reference here. client.set() will not work due to lack of user context.

    0
  • Gaby Bitar

    Ahmed Zaid Great! Do you have an example of how I would use client.request() to update the user end point?

    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Sure. Here is how to suspend a user:

    const options = {
    url: `/api/v2/users/${userId}`,
    type: 'PUT',
    data: JSON.stringify({
    user: {
    suspended: true
    }
    }),
    contentType: 'application/json'
    };

    client.request(options).then(
    (res) => {
    console.log(`Suspended user ${res.user.id}`);
    },
    (res) => {
    console.log(`Error ${res.status}`);
    }
    );

    All you need is userId (string). Hope I didn't make any typos because I didn't run it.

    1
  • Gaby Bitar

    Ahmed Zaid amazing, that worked! Thank you so much for your help. I really appreciate you taking the time to help.

    0
  • Gaby Bitar

    Ahmed Zaid One thing I did notice, the field updates but only after I fully refresh the page. If I try to reload the page using javascript, the updated fields don't reflect. Is there a solution to this?

    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Gaby Bitar, I am happy to help. Unfortunately, I have no solution for the data refresh. I face the same problem myself and my front-end is not good enough to come up with a solution.

    0

Please sign in to leave a comment.

Powered by Zendesk