0

I have a view "Nearest Dealers" that lists all the near dealers. There are two displays - Page & REST Export. I've added a filter(exposed to visitors) that lets customer search dealers based on current location and distance(eg: 10km radius). Filter works perfectly, but I want to show the same filtered results in REST Export display for the same view. Is it possible to do so because I have no clue how to make this work. Or is there any way to add the same filter for the REST Export display ?

2

is there any way to add the same filter for the REST Export display ?

On your regular View page, apply filter for something, and you'll see a URL query gets appended to your URL. For example, when I'm filtering by content type, for mine, I see:

mysite.com/page-view?title=&type=article&status=All&langcode=All (This is based on the view filters I have).

Then all you have to do is append this query to your REST export URL.

mysite.com/rest-export?title=&type=article&status=All&langcode=All (Assuming you have the same filters as your page view, they should've been added by default when you added the REST view).

You'll need to create documentation for this. So people that are using your API know what parameter names & values are accepted.

6
  • Thanks for the help. I tried to append the query string but it doesn't work. I tried using % since it works for contextual filers, but it didn't work for exposed filter. I was thinking, does replacement pattern work on rest export URL ? Oct 20 '20 at 13:27
  • @AmanDevrath make sure you've the same filters in your Rest export, see this demo
    – No Sssweat
    Oct 21 '20 at 5:52
  • That was a total confusion by my side. This way I can get it. In video you copy paste the query string to the rest export url on the browser address bar. Is it possible to get it automatically in the url ? Like no need to copy paste just click the rest export url and see the filter applied in page display ? Oct 21 '20 at 7:11
  • @AmanDevrath you would have to programmatically redirect it, like in this answer; although, that case is for a node, but yours would be similar.
    – No Sssweat
    Oct 22 '20 at 8:12
  • 1
    You can also thank me by accepting the answer with the checkmark and up voting it. I get rep points for that @Aman Devrath
    – No Sssweat
    Oct 23 '20 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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