Json api v1/create multiple records embedded in json file

There is an important difference between what multi-command submissions on the gRPC API provide you with and what a hypothetical matching functionality on the JSON API could provide and what handling this on the client side via a postman library or whatever else provides:

Multi-command submissions on the gRPC API are transactional meaning they result in a single transaction or fail. If you do this on the client-side you will produce one transaction per command.

This has a few implications. Most importantly you loose atomicity by doing it on the client-side. Second, a single transaction with two creates is much cheaper for the ledger than two transactions each with one create. (At some point very large transactions can cause issues but we’re talking about thousands of actions in a single transaction here).

So what do you do if you use the JSON API and you need atomicity or the better performance? Luckily, you don’t need a special endpoint for this. You can handle this via createAndExercise. Here is a simple example of how you can use createAndExercise for the multi-create usecase you described:

template Helper
  with
    p : Party
  where
    signatory p
    choice CreateN : [ContractId T]
      with ts: [T]
      controller p
      do mapA create ts

test = script do
  p <- allocateParty "p"
  submit p $ createAndExerciseCmd (Helper p) (CreateN [T with …, T with …])
6 Likes