spacer
Skip to content

Graph Mail Categories

More information can be found in the official Graph documentation:

IUsers, IUser, IPeople

Invokable Banner Selective Imports Banner

Get All Categories User

import { graphfi } from "@pnp/graph";
import "@pnp/graph/users";
import "@pnp/graph/outlook";

const graph = graphfi(...);

// Delegated permissions
const categories = await graph.me.outlook.masterCategories();
// Application permissions
const categories = await graph.users.getById('{user id}').outlook.masterCategories();

Add Category User

import { graphfi } from "@pnp/graph";
import "@pnp/graph/users";
import "@pnp/graph/outlook";

const graph = graphfi(...);

// Delegated permissions
await graph.me.outlook.masterCategories.add({
  displayName: 'Newsletters', 
  color: 'preset2'
});
// Application permissions
await graph.users.getById('{user id}').outlook.masterCategories.add({
  displayName: 'Newsletters', 
  color: 'preset2'
});

Update Category

Known Issue Banner Testing has shown that displayName cannot be updated.

import { graphfi } from "@pnp/graph";
import "@pnp/graph/users";
import "@pnp/graph/outlook";
import { OutlookCategory } from "@microsoft/microsoft-graph-types";

const graph = graphfi(...);

const categoryUpdate: OutlookCategory = {
    color: "preset5"
}

// Delegated permissions
const categories = await graph.me.outlook.masterCategories.getById('{category id}').update(categoryUpdate);
// Application permissions
const categories = await graph.users.getById('{user id}').outlook.masterCategories.getById('{category id}').update(categoryUpdate);

Delete Category

import { graphfi } from "@pnp/graph";
import "@pnp/graph/users";
import "@pnp/graph/outlook";

const graph = graphfi(...);

// Delegated permissions
const categories = await graph.me.outlook.masterCategories.getById('{category id}').delete();
// Application permissions
const categories = await graph.users.getById('{user id}').outlook.masterCategories.getById('{category id}').delete();