i useing drupal 8. i create ResTful export with views. my site have several content type and i use several views for any content type. but in clinet(android) i need have list with specified numbers...so i cant use Nid(Because i have several content type) how i can add number for every content in my views? (such as this pic that firefox add number(0)to my every content) (upside down number this image) enter image description here

2 Answers 2


You can add a Field in Views that counts the result rows. The Field is called View result counter and you can find it under Global Category.

Humans usually prefer to start count at 1, but there is an option in that Field settings to set the Starting value so you can use zero.

I haven't tried it with Rest export, grouping like in your screenshot won't work. It will just be one of the fields.

  • i think thats what I wanted! but i think drupal have bug for restful export with View result counter ! i.sstatic.net/RPFBE.png Commented Jun 16, 2018 at 14:31
  • Yes it seems there is a bug. What version are you using? Will you report it if you don't find an existing one? drupal.org/project/issues/…
    – prkos
    Commented Jun 16, 2018 at 17:49

Mahdi Baghery, You can customize the JSON response using views plugin that extends Serializer like https://cgit.drupalcode.org/one_api/tree/src/Plugin/views/style/SerializerCount.php

The above SerializerCount.php code is used to add pager to ResTful export like http://one-drupal-demo.technikh.com/onedrupal/api/v1/content?page=1

results: [],
pager: {}

This JSON is parsed by Drupal 8 Android app at https://github.com/onedrupal/One-Drupal-Android. https://play.google.com/store/apps/details?id=com.technikh.onedrupal

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.