Update Project Label Text via Dynamics API

292 Views Asked by At

I'm using the dynamics CRM REST API to create projects, and manage some actions on Microsoft Projects online. We're using labels, which we can apply to tasks, to signify various things.

Via the API I can read labels, and I can read and write the labels that have been assigned to each task (msdyn_projecttask). The bit I haven't succeeded with is creating an API call which will change the text of a label from the default (Pink, Red, Yellow etc.) to something more useful.

Currently I'm having to manually edit the label text via the Project User Interface (e.g. see below).

e.g. project labels

Once I've renamed the label, when I fetch them via the API I can see the changed text, but I can't figure out a way to change it via the API.

I'm able to fetch the project labels via

GET https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/msdyn_projectlabels?$filter=_msdyn_projectid_value%20eq%20%27{projectId}%27 (where {projectId} is the msydn_projectid of my project)

Which returns data like:

{
   "@odata.context":"https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/$metadata#msdyn_projectlabels",
   "value":[
      {
         "@odata.etag":"W/\"21783358\"",
         "_owningbusinessunit_value":".....",
         "statecode":0,
         "msdyn_colorindex":192350000,
         "statuscode":1,
         "_createdby_value":"....",
         "_ownerid_value":".....",
         "_owningteam_value":".....",
         "modifiedon":"2022-11-02T13:32:26Z",
         "_modifiedby_value":"....",
         "versionnumber":21783358,
         "_msdyn_projectid_value":".....",
         "createdon":"2022-11-02T13:32:26Z",
         "msdyn_projectlabelid":"625eb1b2.....",
         "_owninguser_value":null,
         "overriddencreatedon":null,
         "importsequencenumber":null,
         "_modifiedonbehalfby_value":null,
         "msdyn_projectlabeltext": "Label One",
         "utcconversiontimezonecode":null,
         "_createdonbehalfby_value":null,
         "timezoneruleversionnumber":null
      },
....
   ]
}

I've tried:

PATCH https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/msdyn_projectlabels({labelId}}) (where {labelId} is one of the msdyn_projectlabelid values returned above)

headers: [
  "If-Match: *",
  "OData-MaxVersion: 4.0",
  "OData-Version: 4.0",
  "Accept: application/json",
  "Authorization: ...",
  "Content-Type: application/json; charset=utf-8"
]
body: {
    "msdyn_projectlabeltext": "Test Label 1"
}

But it fails and says:

"We\u2019re sorry. You cannot directly do 'Update' operation to 'msdyn_projectlabel'. Try editing it through the Resource editing UI via Project."

And I've tried:

PATCH https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/msdyn_projectlabels

headers: [
  "If-Match: *",
  "OData-MaxVersion: 4.0",
  "OData-Version: 4.0",
  "Accept: application/json",
  "Authorization: ...",
  "Content-Type: application/json; charset=utf-8"
]
body: {
    "msdyn_projectlabeltext": "Test Label 1"
    "[email protected]": "/msdyn_projectlabels({labelId})"
}

Which fails, saying:

"The requested resource does not support http method 'PATCH'."

Also tried:

PUT https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/msdyn_projectlabels({labelId})/msdyn_projectlabeltext

headers: [
  "OData-MaxVersion: 4.0",
  "OData-Version: 4.0",
  "Accept: application/json",
  "Authorization: ...",
  "Content-Type: application/json; charset=utf-8"
]
body: {
    "value": "Test Label 1"
}

Which fails with the same error as above.

There doesn't seem to be any documentation for this anywhere, if you google "msdyn_projectlabel" or "msdyn_projectlabels" (in quotes) you don't get a single result!

Anyone out there have any knowledge on whether this is possible / how to succeed?

1

There are 1 best solutions below

1
Guillem On

This should be done using Project Service Schedule but I am also stuck trying to update.. Project Service Schedule