Support

Expand all | Collapse all

Set position when adding an item (API REST)

Jump to Best Answer
  • 1.  Set position when adding an item (API REST)

    Posted 03-26-2018 02:28
    Hi everybody,

    I just want to know if it is possible to set the position on an item when we add it using API REST ?
    For Exmaple : I  add parent item, then child item "One" , child item "Three" and finally child item "Two" but i want thaht two is after "One" and before "Three". It is possible to set the position of "Two" directly via the PUT request ? Or The only way is to PUT "Two" and then change parent of "Three" two times so it will be under "Two" ?

    Thanks.

    ------------------------------
    Garros JP
    ------------------------------


  • 2.  RE: Set position when adding an item (API REST)

    Posted 04-04-2018 13:40
    Hi JP,

    I would like to make sure I have your question right:

    Here's what you have to start:

    1. Parent
    1.1 Child #1
    1.2 Child #3
    1.3 Child #2

    You'd like the order to be instead:

    1. Parent
    1.1 Child #1
    1.2 Child #2
    1.3 Child #3

    Updating an item's sort order is not supported by our API with a single un-creative call, though I am a little confused on how you learned to work around it, would you mind clarifying which endpoints an field values you are using to do this update?

    We have a PUT /items/{id}/location endpoint that only supports moving an item between projects. You can see the item's existing sort order with the GET /items/{id}/location endpoint.

    Thanks!

    ​​​

    ------------------------------
    Sara Jensen
    Developer Support Engineer
    Jama Software
    Portland OR
    503.922.1058
    ------------------------------



  • 3.  RE: Set position when adding an item (API REST)
    Best Answer

    Posted 04-05-2018 16:16
    Garros,
    You should be able to change the same-level sort order of items by altering  the 'sortOrder' parameter in the item's location data. I have an item with four children; when I run a GET for the first item in the list of children, I see this in the location section:

    "location": { "sortOrder": 0, "globalSortOrder": 924413490, "sequence": "1.5.2.1", "parent": { "item": 6996 }

    when I move it to be the fourth item in the list, I see this:

    "location": { "sortOrder": 3, "globalSortOrder": 967079264, "sequence": "1.5.2.4", "parent": { "item": 6996 }

    You might be able to alter the 'sortOrder' parameter in a POST request, but generally it's best to add items in the order you want them to appear in the UI.

    ------------------------------
    Abby Embree
    Jama Software
    ------------------------------



  • 4.  RE: Set position when adding an item (API REST)

    Posted 04-06-2018 01:22
    Thanks for your answer.

    You're right the sortOrder change when an item is moved. But this is not the only change. The globalSortOrder is also changind and the sequence too. I tried to do ht echnage by using the api-docs page. doing a PATCH request for location/sortOrder the request response is 200 but when I do a GET on my item location sortOrder is not changed.
    It seems more tricky than only change the location/sortOrder.

    Thanks for the idea.

    ------------------------------
    Garros JP
    ------------------------------