Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Microsoft Project schedule API Create operation POST body structure

Posted on by 24

Hi,

I am trying to perform CRUD operations on a Microsoft Project project (https://project.microsoft.com/)

I found the Project schedule API, I can fetch all the tasks but cannot create a task. I get this error:


{
  "error": {
    "code": "0x80048d19",
    "message": "Error identified in Payload provided by the user for Entity :'',

 

I make a request to this endpoint: https://MYORGID.api.crm4.dynamics.com/api/data/v9.1/msdyn_PssCreateV1

What is the issue with my payload?

{
  "Entity": {
    "@odata.type": "Microsoft.Dynamics.CRM.msdyn_projecttask",
    "msdyn_project@odata.bind": "/msdyn_projects(MYPROJECTID)",
    "msdyn_subject": "test",
    "msdyn_scheduledstart": "2024-09-10T00:00:00Z",
    "msdyn_scheduledend": "2024-09-15T00:00:00Z",
    "msdyn_start": "2024-09-10T00:00:00Z",
    "msdyn_projectbucket@odata.bind": "/msdyn_projectbuckets(MPROJECTBUCKETID)",
    "msdyn_LinkStatus": 192350000,
    "msdyn_outlinelevel": 1
  },
  "OperationSetId": "MYOPERATIONSETID"
}


These are the functions that I'm using to make the requests - in a client-side JavaScript app:

import { ensureScope, getToken } from './auth';

export async function getProjectTasks() {
    try {
        const accessToken = await getToken();
        ensureScope(`https://${
        import.meta.env.VITE_MICROSOFT_DYNAMICS_ORG_ID
      }.api.crm4.dynamics.com/.default`);
        if (!accessToken) {
            throw new Error('Access token is missing');
        }

        const apiUrl = `https://${
        import.meta.env.VITE_MICROSOFT_DYNAMICS_ORG_ID
      }.api.crm4.dynamics.com/api/data/v9.1/msdyn_projecttasks`;

        const response = await fetch(apiUrl, {
            method  : 'GET',
            headers : {
                'Authorization'    : `Bearer ${accessToken}`,
                'OData-MaxVersion' : '4.0',
                'OData-Version'    : '4.0',
                'Accept'           : 'application/json',
                'Content-Type'     : 'application/json'
            }
        });

        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }

        const data = await response.json();
        return data;
    }
    catch (error) {
        console.error('Error fetching project entities:', error);
        throw error;
    }
}

export async function createOperationSet(projectId, description) {
    const accessToken = await getToken();
    ensureScope(`https://${import.meta.env.VITE_MICROSOFT_DYNAMICS_ORG_ID}.api.crm4.dynamics.com/.default`);
    if (!accessToken) {
        throw new Error('Access token is missing');
    }

    const apiUrl = `https://${import.meta.env.VITE_MICROSOFT_DYNAMICS_ORG_ID}.api.crm4.dynamics.com/api/data/v9.1/msdyn_CreateOperationSetV1`;

    const payload = {
        'ProjectId'   : projectId,
        'Description' : description
    };

    const response = await fetch(apiUrl, {
        method  : 'POST',
        headers : {
            'Authorization'    : `Bearer ${accessToken}`,
            'OData-MaxVersion' : '4.0',
            'OData-Version'    : '4.0',
            'Accept'           : 'application/json',
            'Content-Type'     : 'application/json'
        },
        body : JSON.stringify(payload)
    });

    if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data = await response.json();
    return data.OperationSetId;
}

export async function createProjectTask(projectId, projectBucketId, operationSetId) {
    const accessToken = await getToken();
    ensureScope(`https://${import.meta.env.VITE_MICROSOFT_DYNAMICS_ORG_ID}.api.crm4.dynamics.com/.default`);
    if (!accessToken) {
        throw new Error('Access token is missing');
    }

    const apiUrl = `https://${import.meta.env.VITE_MICROSOFT_DYNAMICS_ORG_ID}.api.crm4.dynamics.com/api/data/v9.1/msdyn_PssCreateV1`;

    const payload = {
        'Entity' : {
            '@odata.type'                    : 'Microsoft.Dynamics.CRM.msdyn_projecttask',
            'msdyn_project@odata.bind'       : `/msdyn_projects(${projectId})`,
            'msdyn_subject'                  : 'test',
            // "msdyn_effort": '',
            'msdyn_scheduledstart'           : '2024-09-10T00:00:00Z',
            'msdyn_scheduledend'             : '2024-09-15T00:00:00Z',
            'msdyn_start'                    : '2024-09-10T00:00:00Z',
            'msdyn_projectbucket@odata.bind' : `/msdyn_projectbuckets(${projectBucketId})`,
            'msdyn_LinkStatus'               : 192350000,
            'msdyn_outlinelevel'             : 1
            // '@odata.type'                    : 'Microsoft.Dynamics.CRM.msdyn_projecttask',
            // 'msdyn_LinkStatus'               : 192350000,
            // 'msdyn_subject'                  : 'test',
            // 'msdyn_start'                    : '2024-09-10T00:00:00Z', // Example start date
            // 'msdyn_finish'                   : '2024-09-15T00:00:00Z', // Example finish date
            // 'msdyn_project@odata.bind'       : `/msdyn_projects(${projectId})`,
            // 'msdyn_projectbucket@odata.bind' : `/msdyn_projectbuckets(${projectBucketId})`
        },
        'OperationSetId' : operationSetId
    };

    const response = await fetch(apiUrl, {
        method  : 'POST',
        headers : {
            'Authorization'    : `Bearer ${accessToken}`,
            'OData-MaxVersion' : '4.0',
            'OData-Version'    : '4.0',
            'Accept'           : 'application/json',
            'Content-Type'     : 'application/json'
        },
        body : JSON.stringify(payload)
    });

    if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data = await response.json();
    return data;
}
  • Verified answer
    MattDC Profile Picture
    MattDC 24 on at
    Microsoft Project schedule API Create operation POST body structure
    This worked:

    ```
      const payload = {
            'Entity' : {
                // 'msdyn_LinkStatus'               : 192350000,
                'msdyn_subject'                  : 'test',
                'msdyn_start'                    : '2024-09-10T00:00:00Z',
                'msdyn_finish'                   : '2024-09-15T00:00:00Z',
                '@odata.type'                    : 'Microsoft.Dynamics.CRM.msdyn_projecttask',
                'msdyn_project@odata.bind'       : `msdyn_projects(${projectId})`,
                'msdyn_projectbucket@odata.bind' : `msdyn_projectbuckets(${projectBucketId})`
            },
            'OperationSetId' : operationSetId
        };
    ```

    Not sure why '
    msdyn_LinkStatus' is not recognized. I tried some variants of it but I got the same error.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans