To change, or update, a user's information, a PATCH request needs to be made. In thise scenario, we'll update a user's status programmatically. To do so, we'll need to:
- Find our user using a query parameter
- Send the appropiate status ID
- Send a PATCH request to the update a user's status endpoint.
We'll use a helper function to do the first task:
let userId; const useEffect(() => { const userEmail = new URLSearchParams(window.location.search).get('email'); userId = (JSON.parse(localStorage.getItem("users"))).find(u => u.email === userEmail).id; }, [])
With our user ID identified, we can update their status based on input:
const UpdateStatus = async (e) => { e.preventDefault(); try { const data = await fetch( `https://api.zoom.us/v2/contact_center/users/${userId}/status`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', Authorization: 'Bearer YOUR_SECRET_TOKEN', }, body: JSON.stringify({ status_id: statusId, }), }, ); } catch (error) { console.log(`Error: ${error.message}`); } };