0

Trying to add paragraphs via REST to the earlier created node.

I've installed the Paragraphs Type Permissions module, enabled the following permissions for my REST user's role

  • Text: Create content
  • Video: Create content

See: https://www.drupal.org/project/paragraphs/issues/3012600#comment-12851834

but still getting an error 403 and {"message":""} in response while trying to add some paragraphs to the node created earlier.

Error log:

Type        access denied
Date        Monday, December 28, 2020 - 20:40
User        restadmin
Location    https://drupal-8.site/entity/paragraph?_format=hal_json
Referrer    
Message     Path: /entity/paragraph?_format=hal_json. Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 120 of /var/www/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).
Severity    Warning
Hostname    77.139.170.139
Operations

Here JSON for the Text Paragraph:

   {
        "field_text": [
            {
                "value": text,
                "format": "full_html",
                "processed": text
            }
        ],
        "parent_id": [
            {
                "value": str(parent_id)
            }
        ],
        "parent_type": [
            {
                "value": "node"
            }
        ],
        "parent_field_name": [
            {
                "value": "field_paragraphs"
            }
        ],
        "type": [
            {
                "target_id": "text"
            }
        ],
        "_links": {
            "type": {
                "href": base_url + REST_TYPE_PARAGRAPH_TEXT
            }
        }
    }

Here JSON for the Video paragraph:

{
        "field_video": {
            "value": "video:" + str(video_id)
        },
        "parent_id": [
            {
                "value": str(parent_id)
            }
        ],
        "parent_type": [
            {
                "value": "node"
            }
        ],
        "parent_field_name": [
            {
                "value": "field_paragraphs"
            }
        ],
        "type": [
            {
                "target_id": "video"
            }
        ],
        "_links": {
            "type": {
                "href": base_url + REST_TYPE_PARAGRAPH_VIDEO
            }
        }
    }

What permission am I missing here?

1 Answer 1

0

Check on permission Paragraphs Type Permissions -> Bypass Paragraphs type content access control was missing here.

There was also a problem with the JSON request payload of the video paragraph, here the correct version:

    {
        "field_video": [
            {
                "target_id": video_id
            }
        ],
        "parent_id": [
            {
                "value": parent_id
            }
        ],
        "parent_type": [
            {
                "value": "node"
            }
        ],
        "parent_field_name": [
            {
                "value": "field_paragraphs"
            }
        ],
        "type": [
            {
                "target_id": "video"
            }
        ],
        "_links": {
            "type": {
                "href": base_url + REST_TYPE_PARAGRAPH_VIDEO
            },
            base_url +  REST_RELATION_PARAGRAPH_VIDEO_FIELD_VIDEO: [
                {
                    "href": base_url + "/media/%d/edit" % video_id + FORMAT_HAL_JSON,
                    "lang": "en"
                }
            ]
        }
    }

And a correct/working version of the text paragraph JSON payload:

    {
        "field_text": [
            {
                "value": text,
                #"format": "full_html" - getting error "full_html" not recognized
            }
        ],
        "parent_id": [
            {
                "value": str(parent_id)
            }
        ],
        "parent_type": [
            {
                "value": "node"
            }
        ],
        "parent_field_name": [
            {
                "value": "field_paragraphs"
            }
        ],
        "type": [
            {
                "target_id": "text"
            }
        ],
        "_links": {
            "type": {
                "href": base_url + REST_TYPE_PARAGRAPH_TEXT
            }
        }
    }
1
  • After fixing those issues and passing a successful (status: 200) update (patch) to the node, I still cant see those paragraphs in the node. What I'm missing here? Jan 3, 2021 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.