Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

node.js - Microsoft Graph List outlookTask not returning immutable ID even if it's in preferred in header

So in the documentation, it says if you want to get tasks with immutable id instead of normal one just add a header 'Prefer: IdType="ImmutableId"'. I've done that but it still returns tasks with normal ID. It works fine when I try it with outlook events and if I try to get outlook task by ID (get single task instead of listing all). But as soon as I try getting all tasks with immutable id it doesn't work. It doesn't say any error it just returns the data but with the normal id.

Also, I know that outlook tasks API is getting deprecated but todo list API is not going to cut it right now and I've already tried it - there is no way to retrieve any form of immutable ids, just normal ones.

This is the code I use to retrieve all tasks (list all tasks) in NodeJS:

      let response = await client
        .api('/me/outlook/tasks?$top=25000')
        .header("Prefer", "IdType="ImmutableId"")
        .header('Prefer', `outlook.timezone="${timeZone}"`)
        .version('beta')
        .get();

It is very weird because when trying to get one specific task by ID and setting prefer id type header, it works.

Anyway here is how requests look:

LIST OUTLOOK TASKS (GET ALL OUTLOOK TASKS)

GET https://graph.microsoft.com/beta/me/outlook/tasks

GET ONE SPECIFIC TASK VIA ID

GET /me/outlook/tasks/{id}

HEADER FOR GETTING IMMUTABLE IDS INSTEAD OF NORMAL ONES

Prefer: IdType="ImmutableId"

POTENTIONALLY HELPFUL

This is the code I use to retrieve all events with Immutable ID's (this works compared to tasks)

let response = await client.
    api('/me/calendar/events?$top=25000')
    .header('Prefer', `outlook.timezone="${timeZone}"`)
    .header("Prefer", "IdType='ImmutableId'")
    .get();

MS Graph official documentation: How to retrieve a list of outlookTasks

MS Graph official documentation: outlookTask resource type

MS Graph official documentation: event resource type

MS Graph official documentation: Get immutable identifiers for Outlook resources

question from:https://stackoverflow.com/questions/65940751/microsoft-graph-list-outlooktask-not-returning-immutable-id-even-if-its-in-pref

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Okay, so I've found the solution and it's just ridiculous. If any MS Graph SDK developers see this please fix it.

Instead of this:

  let response = await client
    .api('/me/outlook/tasks?$top=25000')
    .header("Prefer", "IdType="ImmutableId"")
    .header('Prefer', `outlook.timezone="${timeZone}"`)
    .version('beta')
    .get();

You MUST do this:

  let response = await client
    .api('/me/outlook/tasks?$top=25000')
    .header("Prefer", `IdType="ImmutableId", outlook.timezone="${timeZone}"`)
    .version('beta')
    .get();

I guess setting the second Prefer header overrides the first one and consequentially only the second one is sent. Unfortunately, I've discovered this right after I implemented the solution via OpenTypeExtension.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...