How to organize the queries create/update relationship-based JSON API?

For example, there are resources "Organizations" and "Contacts". The relationship between the resources is many to many.
The user creates a new organization with a couple of contacts. As based on the current standard json api, to organize queries to the server to create objects?

If I understand correctly the sequence should be:
1. A POST request with the attributes of the organization;
2. POST requests with the attributes of each contact;
3. A POST request to the resource relationships of the organization (/organization/:id/relationships) to associate the organization with contacts. A PATCH request to a resource of the organization and their relationship to recorded contacts.

It is obvious that the queries must be executed sequentially. But what if, for example, after you save the organization an error occurred validation contact on the server? Or if after you save the contact at the client the connection was lost, and the relationship was not recorded? Indeed, in this case the database will organization without contacts and/or contacts with no connection to the organization.
March 23rd 20 at 18:47
0 answer

Find more questions by tags Web DevelopmentRESTful APICRUD