Is there a way to update User API fields in Nav Bar Apps?
I'm creating a Nav Bar app, and I wanted to know if there was a way to update a Users field from it (ex. Role, suspended, etc). I see documentation on updating ticket options in ticket sidebar using client.set().
I am new to this, and would love some help.
Thank you.
-
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.
-
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.
-
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.
-
Ahmed Zaid Great! Do you have an example of how I would use client.request() to update the user end point?
-
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.
-
Ahmed Zaid amazing, that worked! Thank you so much for your help. I really appreciate you taking the time to help.
-
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?
-
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.
Please sign in to leave a comment.
8 Comments