Description of the problem

POSTing a field collection item using Drupal 8 ReSTful API (JSON) generates a 403 error with the following message returned:

{
"message": "You are not authorized to create this field_collection_item entity of bundle field_whats_related."
}

Preliminary Information

Drupal 8.3.4
Field Collection: 8.x-3.x-dev

Using Postman for testing.

Headers used for all operations:

  • x-csrf-token: O3VyNsZJ0F1g1La9CSsHJaH-kwI0oY-qdSk87Vnt8BU
  • Content-Type: application/json
  • Authorization: Basic YXJodXNlcnY6YXJodXNlcnY=

ReST Settings:

Permissions: For the purposes of these tests the authorized user is an administrator

ReST Details

GET http://arhuservclient.dev/field_collection_item/1?_format=json succeeds and provides the structure for the new field collection item:

{
    "item_id": [
        {
            "value": 1
        }
    ],
    "host_type": [
        {
            "value": "node"
        }
    ],
    "uuid": [
        {
            "value": "8fef0c14-6ee0-41de-886e-42c567beaf2b"
        }
    ],
    "revision_id": [
        {
            "value": 1
        }
    ],
    "field_name": [
        {
            "target_id": "field_whats_related",
            "target_type": "field_collection",
            "target_uuid": "f3be72ff-f46f-43a9-a7a5-2c8f552a14dc"
        }
    ],
    "field_category": [
        {
            "value": "News"
        }
    ],
    "field_external_image": [
        {
            "value": "http://arhuserv.dev/sites/default/files/pictures/2017-01/story.jpg"
        }
    ],
    "field_summary": [
        {
            "value": "<p>Vivamus sed vulputate lectus. Vivamus luctus interdum nunc, non gravida ex fermentum id. Phasellus scelerisque, enim vel varius sollicitudin, mauris tellus bibendum augue, ac tempor erat mi vitae odio. Etiam magna arcu, pulvinar interdum mi nec, interdum ornare felis. Curabitur faucibus metus nec tincidunt suscipit.</p>\r\n",
            "format": "basic_html"
        }
    ],
    "field_title": [
        {
            "value": "A News Story",
            "format": "basic_html"
        }
    ]
}

POSTing the following to http://arhuservclient.dev/entity/field_collection_item?_format=json fails:

{

    "host_type": [
        {
            "value": "node"
        }
    ],
    "field_name": [
        {
            "target_id": "field_whats_related",
            "target_type": "field_collection",
            "target_uuid": "f3be72ff-f46f-43a9-a7a5-2c8f552a14dc"
        }
    ],
    "field_category": [
        {
            "value": "News"
        }
    ],
   "field_external_image": [
        {
            "value": "http://arhuserv.dev/sites/default/files/pictures/2017-01/story-1.jpg"
        }
    ],
    "field_summary": [
        {
            "value": "<p>Vivamus sed vulputate lectus. Vivamus luctus interdum nunc, non gravida ex fermentum id. Phasellus scelerisque, enim vel varius sollicitudin, mauris tellus bibendum augue, ac tempor erat mi vitae odio. Etiam magna arcu, pulvinar interdum mi nec, interdum ornare felis. Curabitur faucibus metus nec tincidunt suscipit.</p>",
            "format": "basic_html"
        }
    ],
    "field_title": [
        {
            "value": "<h2>A News Story</h2>",
            "format": "basic_html"
        }
    ]
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

susannecoates created an issue. See original summary.

susannecoates’s picture

Issue tags: +API-First Initiative
susannecoates’s picture

Issue summary: View changes
Wim Leers’s picture

Status: Active » Closed (duplicate)
mlulu’s picture

Hi Susanne,

I'm having the same issue like your, did your issue get solved?

Regards,

vemman’s picture

Why was this closed as per Add normalizers for Field Collection Items (to enable REST/JSON API support) comment #21 this was created specifically?

Anyway any work arounds to properly display field collection via JSONAPI or REST?