Giving not found when trying to add my bot to other user's microsoft team

Alpesh Kanzariya 0 Reputation points
2025-01-02T12:45:46.6366667+00:00
async function addBotToUser(userId) { 
  const YOUR_ACCESS_TOKEN ="token"

  const url = `https://graph.microsoft.com/v1.0/users/${userId}`;
  const headers = { 
    Authorization: `Bearer ${YOUR_ACCESS_TOKEN}`, 
    'Content-Type': 'application/json'
  }; 

  const body = { "teamsApp@odata.bind": `https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/7eaf42b9-cf06-4d8d-b51d-20fabb7bbbb6` }; 

  try {
    const response1 = await axios.get(url, {
      headers: {
        Authorization: `Bearer ${YOUR_ACCESS_TOKEN}`,
        'Content-Type': 'application/json'
      }
    });
    const response = await fetch(url, {
      method: 'POST',
      headers: headers,
      body: JSON.stringify(body),
    });
    if (!response.ok) {
      const errorData = await response.json();
      console.error('Error:', errorData);
      throw new Error(`HTTP error! Status: ${response.status}`);
    }

    console.log('App added successfully:', await response.json());
  } catch (error) {
    console.error('Error adding bot to user:', error);
  }

}

The above thing is always gives not found error

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,862 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 44,851 Reputation points
    2025-01-03T02:41:04.43+00:00

    Hi @Alpesh Kanzariya

    Your API url is wrong. It should be:

      const url = `https://graph.microsoft.com/v1.0/users/${userId}/teamwork/installedApps`;
      const headers = { 
        Authorization: `Bearer ${YOUR_ACCESS_TOKEN}`, 
        'Content-Type': 'application/json'
      }; 
    

    API source: https://learn.microsoft.com/en-us/graph/api/userteamwork-post-installedapps?view=graph-rest-1.0&tabs=http#example-1-install-an-app-for-a-user.


    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.