Skip to content

Deserializing a Resource Object/Relationship on create throws an error when no ID is provided #21

Open
@hugofloss

Description

@hugofloss

I'm trying to create a new resource with an existing template relationship and an address relationship that should become a new resource. Example POST request:

{
  "data": {
    "type": "post",
    "attributes": {
      "title": "foo"
    },
    "relationships": {
      "template": {
        "data": {
          "type": "templates",
          "id": "1"
        }
      },
      "address": {
        "data": {
          "type": "addresses",
          "first_name": "John",
          "last_name": "Doe"
        }
      }
    }
  }
}

Because the address relationship does not contain an ID, it throws the following error:

A resource identifier object MUST contain ['id', 'type'] members.

I get that, because the JSON:API documentation clearly states:

A resource object MUST contain at least the following top-level members:
- id
- type

However, the documentation contains an important exception:

Exception: The id member is not required when the resource object originates at the client and represents a new resource to be created on the server.

That's exactly what I'm doing. Can we create an exception for this, or is this is incorrect way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions