How can I use the API to move Cards from one Collection to another?

  • 4 February 2021
  • 4 replies
  • 101 views

Userlevel 1
Badge
Hi everyone! 👋
My team and I are doing a big organizational overhaul of our Guru instance that is going to involve changing up our collections, redoing our naming conventions, and setting up a new tagging system to make everything more scalable. I'm working on setting everything up so we can do this via the API when we're ready and am ALMOST there, but am running into some difficulties moving a card from one collection to another (with the API).
Here's the JSON I'm sending to the Cards endpoint:
```//create JSON
let json = {
"tags":tags,
"collection":{"id":collectionId},
"content": content,
"shareStatus":"TEAM",
"preferredPhrase":cardName
};```
`collectionId` is a string, and exists in Guru. I'm getting a 200 response back from my PUT request, but the collection assigned to the card remains unchanged (all of the other elements update as expected). Is this because the card is already assigned to a Collection and a Board?
Thanks for any pointers!

4 replies

Userlevel 4
Badge
Hi Nathan! Are you doing this in bulk? for example, would you be able to leverage card manager to move an entire collection of cards from collection a to collection b?
Does the existing card already live in a board within the existing collection? You're theory is correct that a card cannot live in multiple collections, so you may need to also need to update the board ID to either null or a desired board ID in the new collection. Let me raise this to our technical support team (don't worry, not YOUR technical support team :slightlysmilingface: ) to confirm.
Userlevel 1
Badge
Thanks for the tips, Mary! Yes, we're doing it in bulk, but not on a collection or even board scale. I wish it was as easy as that 😆 We're changing from more subject-based collections to support tier-based collections, so everything is mixed.
I'll experiment with setting the board ID to null before making the rest of the changes — I had tried to the new board and collection IDs simultaneously, but got an error message that the new board wasn't in the existing card's collection.
Userlevel 4
Badge
Do the subjects have similar naming conventions? Or are they all using the same tag? perhaps if it is done that way, you can leverage the card manager to filter on "tag contains x" or "title contains x"?
I did hear back from the engineering team and the api call does nothing with the collection ID on the inbound card. We would suggest using a different endpoint if it works for you:
`POST https://api.getguru.com/api/v1/cards/bulkop`
You will need to include the below JSON payload in your request listing all card IDs you want to move:
```{"action":{"type":"move-card","collectionId":"DESIREDCOLLECTIONID"},"items":{"type":"id","cardIds":["CARDID1","CARDID2"]}}```
You can still use your existing JSON request for updating the card title and tags if you want and once that is complete, you can bulk move all the cards at once to a new collection.
Userlevel 1
Badge
That's perfect! The new endpoint works like a charm. Thank you so much 🙌

Reply