REST: Add multiple cards to a class

Hello,

is there a chance to create multiple cards at once via REST? Following situation: cmdbdemo available. Created a class “testclass” with two cards (no additional attributes, just ID and Description). When I query the cards via REST, I get the following result (meta truncated):

{
“data”: [
{
“Code”: null,
“Description”: “Record_1”,
“Notes”: null,
“_beginDate”: “2020-09-28T14:44:34.019897Z”,
“_id”: 123,
“_type”: “testclass”,
“_user”: “admin”
},
{
“Code”: null,
“Description”: “Record_2”,
“Notes”: null,
“_beginDate”: “2020-09-28T14:45:12.558551Z”,
“_id”: 345,
“_type”: “testclass”,
“_user”: “admin”
}
]
}

Then I stored the result in a dedicated file and replaced Record_1 with Record 3 and Record_2 with Record 4, changed the ID’s:

{
“data”: [
{
“Code”: null,
“Description”: “Record_3”,
“Notes”: null,
“_beginDate”: “2020-09-28T14:44:34.019897Z”,
“_id”: 1559000,
“_type”: “testclass”,
“_user”: “admin”
},
{
“Code”: null,
“Description”: “Record_4”,
“Notes”: null,
“_beginDate”: “2020-09-28T14:45:12.558551Z”,
“_id”: 2100000,
“_type”: “testclass”,
“_user”: “admin”
}
]
}

When I now try to add the new cards, I get only one new cards called “testclass”, but not Record_3 or Record_4:

curl -d @cards.json --cookie “CMDBuild-Authorization=mqoko9pwjm7pfgn0rbbtjhlk” -X POST -H “Content-Type: application/json”
http://server:8080/cmdbdemo/services/rest/v3/classes/testclass/cards | python -m json.tool

{
“Code”: null,
“Description”: null,
“Id”: 778582,
“IdClass”: “testclass”,
“IdTenant”: null,
“Notes”: null,
“_beginDate”: “2020-10-16T15:55:44”,
“_id”: 778582,
“_type”: “testclass”,
“_user”: “admin”
}

Is there any chance to upload an data array? Card per card works, but is way to slow.
Btw. when I repeat the command to add cards, I get additional cards called testclass inside the class testclass.

Thanks,
Marek

Hello again,

after a couple of days with testing and trying different things, I came to the conclusion that it is not possible to upload an array to create multiple cards at once.

Things I have tried:

  • Format the json in many different ways, sometimes in wrong ways (on purpose)
  • Removed the lines with a leading _ from the json file
  • Used different clients (curl and ARC for Chrome)

The results were always the same:

  • Java Exception (…caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.util.LinkedHashMap: no String-argument constructor/factory method to deserialize from String value…)
  • Empty card created
  • Only the first card created

Also the documentation does not mention how to create multiple cards at once, it is only documentated that “a card” can be created.

Too bad, adding multiple cards at once would really help to automate a few things.

Thanks,
Marek