What's the recommended design for an endpoint that accepts a nested resource as the following:
POST /account
{
"name": "Project John Doe",
"description": "Description of the account...",
"type": "corporate",
"relation_number": "PR2022-1509-8",
"contacts": [
{
"firstname": "John",
"insertion": "",
"lastname": "Doe",
"email": "john.doe@example.com",
"phone_mobile": "1234567890",
"phone_steady": null,
"street": "Foo Street",
"building_number": "12-A",
"postal_code": "123456AB",
"city": "Foobar",
"country": 19,
"priority_level": 1
}
]
}
The requirement is that when an account is created, at least one account contact person must be present.
There are two common options, but I wonder which one should be used:
Creating one endpoint that accepts a POST request containg the JSON as shown above. Thus, accepting a nested object.
Creating two endpoints,
POST /account
andPOST /account/contact
The client is responsible for creating an account in one request, and then create a contact person using a second request. Some sources on the internet suggest to take this approach. But, when a client just doesn't/couldn't send that second POST request to create a contact person for the just created account, the data is inconsistent.
How should this be designed to comply with the guidelines?