1

In docu. There is an example how to create some kind of relation between packages but there is nothing about creating a parent child relation. Maybe someone knows how to do this?

This is what is available in the docu:

enter image description here

and these are the only available relations:

enter image description here

How to make the Parent <-> Child relation so that it looks like this in open project:

enter image description here

lewis4u
  • 14,256
  • 18
  • 107
  • 148

1 Answers1

1

Although parent-child relations are in fact relations (conceptually and in the db), they are not treated as such in the API (mostly for historic reasons).

Therefore, one needs to set the parent via the work package resource. A minimal payload on a PATCH to /api/v3/work_packages/:id (the work package to become the child) would look like this:

{
  "lockVersion": [the correct version],
  "_links": {
    "parent": {
      "href": "/api/v3/work_packages/[ID of the work package to become the parent]"
    }
  }
}

Edit

There is actually an example in the API documentation. You need to open the "Request" example for the PATCH to `/api/v3/work_packages/:id to see it, though.

ulferts
  • 2,187
  • 12
  • 19
  • It's the lockVersion the WorkPackage resource currently has. This is done to prevent conflicting modifications by users without them noticing. BTW: The api also provides [forms](http://docs.openproject.org/apiv3-doc/#forms) to help a client prevent errors. There exist specific forms for [create](http://docs.openproject.org/apiv3-doc/#work-packages-work-package-create-form-post) and [edit](http://docs.openproject.org/apiv3-doc/#work-packages-work-package-edit-form-post) so taking the payload resource from there would always be a good start for a client. – ulferts Apr 18 '18 at 08:28
  • I have tried with multiple lock numbers but I always get an error something about parallel access....does that mean that i was always using the wrong lock version? – lewis4u Apr 18 '18 at 08:58
  • Yes, that is right. If you are certain to use the right lockVersion (the one the work package itself has currently when getting it via a GET), I'd assume that your payload does not have the correct structure. – ulferts Apr 18 '18 at 09:11