Forum Discussion

Saitir's avatar
Saitir
Copper Contributor
Aug 17, 2023

Unable to add a parent when creating an item in Devops REST api - on premises

Adding some automation to our internal devops processes, and most things are working just fine, e.g., creating Epics, Features, Stories, Tasks. Creating iterations and adding work items to them also works just fine, as well as things like adding an Iteration to a team.

However, trying to parent an new User Story to a Feature (or any other relation) keeps failing.

Calling to:

http://mytfsserver:8080/tfs/myfirstcollection/myfirstproject/_apis/wit/workitems/$user%20story?api-version=6

JSON

 

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "My First Title"
  },
  {
    "op": "add",
    "path": "/fields/System.Description",
    "from": null,
    "value": "We can add a description to the item here if we wish."
  },
  {
    "op": "add",
    "path": "/fields/System.IterationPath",
    "from": null,
    "value": "MyFirstProject\My First Iteration"
  },
  {
    "op": "add",
    "path": "/relations/-",
    "value": {
    "rel": "System.LinkTypes.Hierarchy-Reverse",
    "url": "http://mytfsserver:8080/tfs/myfirstcollection/myfirstproject/_apis/wit/workitems/526"
    }
  }
]

 

 

This yields the error:

 

{
  "innerException": null,
  "message": "Value [  {    "op": "add",    "path": "/fields/System.Title",    "from": null,    "value": "My First Title"  },  {    "op": "add",    "path": "/fields/System.Description",    "from": null,    "value": "We can add a description to the item here if we wish."  },  {    "op": "add",    "path": "/fields/System.IterationPath",    "from": null,    "value": "myfirstproject\My First Iteration"  },  {    "op": "add",    "path": "/relations/-",    "value": {    "rel": "System.LinkTypes.Hierarchy-Reverse",    "url": "http://mytfsserver:8080/tfs/myfirstcollection/myfirstproject/api/wit/workitems/526"    }  }] does not match the expected type Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItemRelation.",
  "typeName": "Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common",
  "typeKey": "VssPropertyValidationException",
  "errorCode": 0,
  "eventId": 3000
}

 

If I submit the same thing without the relation, the user story is created correctly.

Its Devops 2020, and while the URLs are slightly different to a cloud hosted Azure Devops, as far as I can tell there's no real functionality difference.

All the corrections and fixes I can find so far indicate that the wrong linktype hierarchy is used, but as far as I can tell this the same as any samples I've seen.

All ideas welcome.

I've tried a number of variations, including pretty much copy and pasting examples and just tweaking for the server/project names.

When the relation is included I get the error, without I don't.

 

Has any one managed this with on premises?  Would an upgrade to 2022 make a difference?

1 Reply

  • How about this:

     

    [
      {
        "op": "add",
        "path": "/fields/System.Title",
        "value": "My First Title"
      },
      {
        "op": "add",
        "path": "/fields/System.Description",
        "value": "We can add a description to the item here if we wish."
      },
      {
        "op": "add",
        "path": "/fields/System.IterationPath",
        "value": "MyFirstProject\\My First Iteration"
      },
      {
        "op": "add",
        "path": "/relations/-",
        "value": {
          "rel": "System.LinkTypes.Hierarchy-Reverse",
          "url": "http://mytfsserver:8080/tfs/myfirstcollection/_apis/wit/workitems/526"
        }
      }
    ]

     

Resources