Search code examples
web-servicesrestdrupaldrupal-7

Choose language using views services in drupal 7


I use views services module with rest services. The views shows content using "current user's language" but when I get content always returns in the default language.

For example:

http://example.com/api1_rest/views/content_view?id_display=page&limit=10&offset=0

Returns

[  
   {  
      "vid":"300",
      "uid":"4",
      "title":"node title",
      "log":"",
      "status":"1",
      "comment":"0",
      "promote":"0",
      "sticky":"0",
      "nid":"2488",
      "type":"news",
      "language":"en",
      "revision_timestamp":"1422900078",
      "revision_uid":"1",
      "body":{  
         "en":[  
            {  
               "value":"content body here",
               "summary":"",
               "format":"4"
            }
         ]
      },
}
]

I need choose language in rest petition.


Solution

  • From Services Views module page:

    You can create exposed filters and pass them to your resource. For example if we created exposed filter "tags" call will be: http://example.com//?tags=7

    So you can create a exposed filter for language in your view and than just filter results by adding &lang=en to the url:

    http://example.com/api1_rest/views/content_view?id_display=page&limit=10&offset=0&lang=en