1

I am setting up an API using Drupal 7, Services module and services views module. I have got this largely set up and working fine.

I have also installed the module: Node Resources (https://www.drupal.org/project/references) which allows me to associate one node with another. For example, I have a content type called 'Companies' and content type called 'Metrics'. I have added a company node called 'Joe Bloggs Ltd' and have added a metric node 'Employees'. When I set up the metric node I selected 'Joe Bloggs Ltd' from the dropdown.

I have set up a service using service module and service-views (configured fields) to show a list of metrics when I hit: http://example.com/api/metrics/ I get the following:

<result is_array="true">
    <item>
        <title>Employees</title>
        <nid>19</nid>
        <metric>10,000</metric>
        <node is_array="true">
            <item>Joe Bloggs Ltd</item>
        </node> 
    </item>
    <item>
        <title>Employees</title>
        <nid>2000</nid>
        <metric>20,000</metric>
        <node is_array="true">
            <item>Geoff Bills Ltd</item>
        </node> 
    </item>
</result>

So far so good - however I want to be able to filter these records by the company node. (To be able to go to : /api/metrics/?company=Joe Bloggs Ltd

I thought this would be straight forward as I've done it with taxonomies etc straight forward. I added the Node (field_metric_node) to the 'Filter Criteria Section' and opened it up for exposure as follows:

Pic 1 Pic 2

I set the arg value to be 'company'

Pic 3

And end up with something like this

Pic 4

However when I go to the api endpoint and send the parameter ?company=Joe Bloggs Ltd

I get a blank XML returned.

Any ideas?

  • Does it returned correct output in views path? Did you check that? – Krishna Mohan Jul 2 '14 at 14:26
  • Like the service - it shows all of the data fine with no filter. But if I add the filter: company=Joe Bloggs Ltd I get an error: "An illegal choice has been detected. Please contact the site administrator." – elnariz Jul 2 '14 at 14:35
  • Hi Krishna - that tip has helped a lot - I think I can see the problem now in that it's taking the nid rather than the title - will post solution shortly...thanks – elnariz Jul 2 '14 at 14:40

Your Answer

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

Browse other questions tagged or ask your own question.