Creating Classes from EDU Graph API

Chibu 46 Reputation points
2021-04-26T08:16:05.167+00:00

Hello everyone, I am faced with this error "Object reference not set to an instance of an object"

When ever i try creating classes calling the Education Graph API,

you can please check out the following screenshots of the issue

** the 154kb screenshot-images can't upload for some reasons i don't know***

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,113 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.
3,295 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Marc LaFleur 86 Reputation points
    2021-05-12T16:59:30.04+00:00

    The 403 - Forbiden response is due to a combination of the Permission Scopes and OAuth Grant you're requesting.

    Creating an educationClass requires an Application (aka App-Only) rather than Delegated (aka App+User) scopes. Since Graph Explorer only supports Delegated scopes, it cannot be used for this operation.

    The type of scopes you receive is determined by the OAuth Grant you use to obtain the token:

    OAuth Grant Permission Type
    Authorization Code Delegated
    Client Credentials Application
    Implicit Flow Delegated
    Password Grant Delegated

    Note that with Application scopes there is no "user" so you also cannot use Me (Graph has no way of knowing which user it should map to).

    var educationClass = new EducationClass
    {
        Description = "Math Level 1",
        ClassCode = "Math 501",
        ExternalId = "11019",
        ExternalName = "Math Level 1",
        ExternalSource = EducationExternalSource.Manual,
        MailNickname = "math501"
    };
    
    await graphClient // using token acquired using client_credentials
        .Education
        .Classes
        .Request()
        .AddAsync(educationClass);
    
    0 comments No comments

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.