Hi,
I am trying to perform CRUD operations on a Microsoft Project project (https://project.microsoft.com/)
I found the , 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; }