Microsoft Teams Export API Error

Hamidreza Nasiri 5 Reputation points

I want to export my data from Microsoft Teams, using Export APIs.

Based on these two guides:

First, I filled the request form to get access to the protected Export APIs, and received the approval email after a week.
I registered the App in Azure Active Directory App Registration section,
User's image

and configured the required permissions:
User's image

After that, I successfully got an authorization code using the GET request provided in the guide:
except that i removed the code_challenge fields,
User's image

Then I used that authorization code to get an access token using POST, according to guide, but I removed the code_verifier field due to an error. With this, I successfully got the access token.

Finally when I tried to get the channel messages using the following request with bearer token from previous step:

I get the error below:

    "error": {
        "code": "PreconditionFailed",
        "message": "Requested API is not supported in delegated context",
        "innerError": {
            "date": "2023-04-08T08:21:11",
            "request-id": "f67e539c-9f17-404e-9f56-d7b10a48e0a8",
            "client-request-id": "f67e539c-9f17-404e-9f56-d7b10a48e0a8"

Would you please help me to solve my problem?
Thanks in advance.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,888 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,925 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. VasimTamboli 4,420 Reputation points

    Hi Hamidreza,

    Based on the error message, it seems that the API you are trying to access does not support delegated context, which means that you cannot use delegated permissions to access the API. Instead, you need to use application permissions to access this API.

    To fix this issue, you should modify the permission settings for your Azure Active Directory App Registration and add the necessary application permissions to access the required API. You can refer to the following guide to learn how to add application permissions to your app:

    Once you have added the necessary permissions to your app, you should use the appropriate authentication flow to obtain an access token with application permissions. You can refer to the following guide to learn how to use the client credentials flow to obtain an access token with application permissions:

    After obtaining the access token, you should use it to make the API request to retrieve the channel messages.

    I hope this helps!

    3 people found this answer helpful.
    0 comments No comments

  2. Hamidreza Nasiri 5 Reputation points


    Thanks for your response.

    I already added API permissions and got access tokens. according to the guides in my first post. I read the guides you sent, and they have some differences with guides that I followed.
    In particular, the first guide you sent suggests that the API permissions should be added using the App role UI, but the guide in my first post suggests that it should be added using API permissions section.
    I completely confused because I followed a guide provided in the Microsoft Teams Export API main page, and spent about a week to exactly implement that, and now you say there is another guide....

    Would you please tell me what is the difference?

    Thanks very much for your help.

    1 person found this answer helpful.

  3. Hamidreza Nasiri 5 Reputation points

    Hi. Thanks for your response.

    0 comments No comments