[Python] "The requested item is not found"; Azure AD Application using Python with Planner

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have an Azure AD Daemon application that is attempting to grab tasks from a desired planner. I've gone ahead and provided the necessary application permissions to try and grab the plan. I keep getting a "The requested item is not found" error despite using the correct Planner ID to grab the data. Is there a permission that I am missing or an issue with my code? I typically use VS code to run the python file with the command python application.py parameters.json.

    Below is the python code I run for the application.

    import sys # For simplicity, we'll read config file from 1st CLI param sys.argv[1]
    import json
    import logging

    import requests
    import msal


    # Optional logging
    # logging.basicConfig(level=logging.DEBUG)

    config = json.load(open(sys.argv[1]))

    # Create a preferably long-lived app instance which maintains a token cache.
    app = msal.ConfidentialClientApplication(
    config["client_id"], authority=config["authority"],
    client_credential=config["secret"],
    # token_cache=... # Default cache is in memory only.
    # You can learn how to use SerializableTokenCache from
    # https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
    )

    # The pattern to acquire a token looks like this.
    result = None

    # Firstly, looks up a token from cache
    # Since we are looking for token for the current app, NOT for an end user,
    # notice we give account parameter as None.
    result = app.acquire_token_silent(config["scope"], account=None)

    if not result:
    logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
    result = app.acquire_token_for_client(scopes=config["scope"])

    if "access_token" in result:
    # Calling graph using the access token
    graph_data = requests.get( # Use token to call downstream service
    config["endpoint"],
    headers={'Authorization': 'Bearer ' + result['access_token']}, ).json()
    print("Graph API call result: ")
    print(json.dumps(graph_data, indent=2))
    else:
    print(result.get("error"))
    print(result.get("error_description"))
    print(result.get("correlation_id")) # You may need this when reporting a bug


    Below is the parameters.json I use with the various ID's required for the application to run

    {
    "authority": "https://login.microsoftonline.com/tenant_id",
    "client_id": "client_id",
    "scope": [ "https://graph.microsoft.com/.default" ],
    "secret": "Secret_Client",
    "endpoint": "https://graph.microsoft.com/v1.0/planner/plans/plan_id"
    }


    The id names are only placeholders, just imagine them being in there.

    Here are the perms currently assigned to the application. Help would be appreciated. [​IMG]

    Continue reading...

Compartilhe esta Página