question

Chibu-3202 avatar image
1 Vote"
Chibu-3202 asked saldana-msft edited

Creating Classes from EDU Graph API

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***



office-teams-app-devmicrosoft-graph-teamworkmicrosoft-graph-education
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Added related tags/teams to assist.

Please share the API call that you use and the error (requestid, timestamp) that you get.

0 Votes 0 ·

92652-screenshot-61.png92584-screenshot-60.png92585-screenshot-62.png


92637-screenshot-55.png


using the graph explorer, i consented to the necessary application permission

0 Votes 0 ·
screenshot-60.png (112.2 KiB)
screenshot-62.png (106.8 KiB)
screenshot-55.png (129.7 KiB)
screenshot-61.png (108.3 KiB)

1 Answer

mlafleur-msft avatar image
0 Votes"
mlafleur-msft answered

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);
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.