0

How do I get all the comments posted for a node? The REST API seems not to return them in a usable manner.

    {
  "_links": {
    "self": {
      "href": "http://localhost:8080/drupal8/node/3?_format=hal_json"
    },
    "type": {
      "href": "http://localhost:8080/drupal8/rest/type/node/article"
    },
    "http://localhost:8080/drupal8/rest/relation/node/article/uid": [
      {
        "href": "http://localhost:8080/drupal8/user/1?_format=hal_json",
        "lang": "en"
      }
    ],
    "http://localhost:8080/drupal8/rest/relation/node/article/revision_uid": [
      {
        "href": "http://localhost:8080/drupal8/user/1?_format=hal_json"
      }
    ]
  },
  "uuid": [
    {
      "value": "5326216b-0e65-454b-8a48-720b6e6e2402"
    }
  ],
  "type": [
    {
      "target_id": "article"
    }
  ],
  "langcode": [
    {
      "value": "en",
      "lang": "en"
    }
  ],
  "title": [
    {
      "value": "Testing Post Article",
      "lang": "en"
    }
  ],
  "_embedded": {
    "http://localhost:8080/drupal8/rest/relation/node/article/uid": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8080/drupal8/user/1?_format=hal_json"
          },
          "type": {
            "href": "http://localhost:8080/drupal8/rest/type/user/user"
          }
        },
        "uuid": [
          {
            "value": "e7f777b9-8bd7-4f87-a100-d1784d6ed1bc"
          }
        ],
        "lang": "en"
      }
    ],
    "http://localhost:8080/drupal8/rest/relation/node/article/revision_uid": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8080/drupal8/user/1?_format=hal_json"
          },
          "type": {
            "href": "http://localhost:8080/drupal8/rest/type/user/user"
          }
        },
        "uuid": [
          {
            "value": "e7f777b9-8bd7-4f87-a100-d1784d6ed1bc"
          }
        ]
      }
    ]
  },
  "status": [
    {
      "value": "1",
      "lang": "en"
    }
  ],
  "created": [
    {
      "value": "1490939860",
      "lang": "en"
    }
  ],
  "changed": [
    {
      "value": "1490939860",
      "lang": "en"
    }
  ],
  "promote": [
    {
      "value": "1",
      "lang": "en"
    }
  ],
  "sticky": [
    {
      "value": "0",
      "lang": "en"
    }
  ],
  "revision_timestamp": [
    {
      "value": "1490939860"
    }
  ],
  "revision_translation_affected": [
    {
      "value": "1",
      "lang": "en"
    }
  ],
  "default_langcode": [
    {
      "value": "1",
      "lang": "en"
    }
  ],
  "body": [
    {
      "value": "article",
      "format": null,
      "summary": null,
      "lang": "en"
    }
  ],
  "comment": [
    **{
      "status": "2",
      "cid": "3",
      "last_comment_timestamp": "1490944700",
      "last_comment_name": "",
      "last_comment_uid": "1",
      "comment_count": "2",
      "lang": "en"
    }**
  ]
}

As can be seen it gives a count but not the Ids of the Comments..

I am using Drupal 8.0.2

1

1 Answer 1

1

I got a solution.

  1. Create a view with rest export with below settings. VIEW SETTINGS: show = comments and type = all

  2. After view is created the change the entity with fields in format settings

  3. Then add the required fields in view, also select content type field so that you can differenciate between comments.

  4. Add contexual filter with id, add change path with {yourpath}/%

  5. Check output on Postman or any other app.

This is working for me,and becuase of this I can able to get the comments related to individual content.

If you want comment related to article content type then you can add the filter criteria.

Hope this will work for you!

Your Answer

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

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