Add Parent Card via API

I am little confused. I want to create cards via API (works fine), but want to include the parent …

I clicked through the API Docs and tried different things but couldn’t work it out.

So my json object is this:

{
  "name": "Aktuelles Datum",
 "markup":"**in der SR-Einheit:**\n\n**heute bearbeitet:**",
  "parents":{"parent_id": "ACTUAL-ID"}
}

The format is mildly confusing, but like with the card creation endpoint in general, the “parents” object is actually keyed by the parent card IDs themselves. Also it looks like you want to use the “simple” card creation endpoint, but for adding parents at creation time you would need to use the more comprehensive Create Cards endpoint.

That being said, for now it might be easier to just use the simple creation endpoint then modify your card after the fact, like so:

POST /v1/cards/simple

{
  "name": "Aktuelles Datum",
  "markup":"**in der SR-Einheit:**\n\n**heute bearbeitet:**",
}

PATCH /v1/cards (using ID returned from last request)

{
  "CARD_ID_FROM_SIMPLE": {
    "parents": {
      "ID_OF_PARENT_CARD": { "publishing_perms": -1 }
    }
  }
}

As this seams like a relatively common use-case, I’ll go ahead and make a note to allow parent addition via the “simple” create endpoint.

Also we started working on some new Developer docs a few days ago, so check them out here and let us know what you think. There is not much there yet so we will definitely be fleshing everything out over time, but please let us know what you think we should add!

Thanks! I also could use the Create Card endpoint.
I am using iOS Shortcuts at the moment, because those can be part of automation and I like to automate creating cards which I need everyday.

So I can’t attach the parent to a card which I am creating at the same time? The card has to be created and then I have to add the parent via patch, is this correct?

Nope, you can, you just need to use the full creation endpoint. Just use the above “parents” format in your creation request – it is the same format as you would use for a PATCH (update) request.

Or wait, are you asking if you can create a card and use it as a parent in the same request? e.g. you want to create two cards in one request, one of which is the child of the other?

No - I have the parent already. Every morning I am creating a card with the current date and setting the parent manually and now I want to automate this action.

Then yes, that will work. Like this:

POST /v1/cards

{
  "ddbcc86a-248d-4504-b66f-5561349a37c4": {
    "data": {
      "id": "ddbcc86a-248d-4504-b66f-5561349a37c4",
      "name": "Aktuelles Datum"
    },
    "membership": {
      "id": "58d2b2e0-b0e8-4c54-a1ae-9d476f12e615"
    },
    "parents": {
      "cffc34d4-cb02-45fa-bc50-ed4bce4a6d66": {
        "publishing_perms": -1
      }
    }
  }
}

I’m obviously stumped today - I don’t understand how I can get the first ID and what the Membership ID is.

I already have the parent ID - but the new child should be created automatically (so I don’t know the ID yet) and then linked directly to the parent during creation.

Yup, that is why it might be better to continue using the simple endpoint for now and then modifying afterwards. For the complete creation endpoint you need to generate the IDs (uuid4) yourself.

It is not currently possible to utilize the simple endpoint (where you don’t need to specify your own UUIDs and other extraneous data) with parents.

We’ve added a parent_ids field to the SIMPLE card create endpoint in 3.0.5, which allows you to very simplify specify any parent card IDs you’d like (as an array) when creating a card via /simple.

e.g.

{
  "name": "Aktuelles Datum",
  "markup":"**in der SR-Einheit:**\n\n**heute bearbeitet:**",
  "parent_ids": ["ACTUAL-ID"] 
}

Hope that helps @isaiur!

1 Like

That works! Thank you so much - yesterday I built a workaround but that’s even better!