Forum

Thread tagged as: Problem, Api, Runway

Runway - Headless requests - issues

Latest Runway - 3.0.12

Just playing around with the headless api and have run into two issues:

1) default collection template that includes categories tags causes error:
From my error log:

PHP Fatal error:  Uncaught Error: Call to a member function to_array_for_api() on boolean in /var/www/rugbyheritage/cms/core/lib/PerchFieldTypes.class.php:2565
Stack trace:
#0 /var/www/rugbyheritage/cms/core/runway/apps/content/PerchContent_Runway.class.php(499): PerchFieldType_category->get_api_value(Array)
#1 /var/www/rugbyheritage/cms/core/lib/api/PerchAPI_ContentCollection.class.php(31): PerchContent_Runway->get_collection('season', Array)
#2 /var/www/rugbyheritage/cms/templates/api/players.php(10): PerchAPI_ContentCollection->query(Array)
#3 /var/www/rugbyheritage/cms/core/runway/start.php(43): include('/var/www/rugbyh...')
#4 /var/www/rugbyheritage/cms/core/runway/start.php(47): perch_runway_dispatch_page(Object(PerchRoutedPage))
#5 {main}
  thrown in /var/www/rugbyheritage/cms/core/lib/PerchFieldTypes.class.php on line 2565

(the collection it is querying is 'Players' and the categories id it references in the template is 'season', as per #1 above)
If I force it use a template that does not include category tags, there is no error.

2) the response is being paginated:
The response shows the first line as:

{"status":"ok","sets":{"players":[{"_id":"1","firstname":"Charlie","lastname":"Amesbury","season":["1","2","3","4"],"fullname":"Amesbury, Charlie","_title":"Amesbury, Charlie","_sortvalue":"1000","paging":false,"total":"10","number_of_pages":1,"total_pages":1 ,"per_page":10,"current_page":1,"lower_bound":1,"upper_bound":10,"prev_url":"","next_url":"", "prev_page_number":"","next_page_number":"","first_page_url":"\/api\/players", "last_page_url":"\/api\/players","first_page":true,"last_page":true},

and the resulting database query is:

SELECT * FROM ( SELECT  idx.itemID, ci.collectionID, ci.itemJSON,  idx2.indexValue as sortval  FROM runway_collection_index idx 
JOIN runway_collection_items ci ON idx.itemID=ci.itemID AND idx.itemRev=ci.itemRev AND idx.collectionID=ci.collectionID
JOIN runway_collection_revisions cr ON idx.itemID=cr.itemID AND idx.itemRev=cr.itemRev AND idx.collectionID=ci.collectionID
JOIN runway_collection_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order'  WHERE (idx.collectionID=1) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev
) as tbl GROUP BY itemID, itemJSON, sortval  ORDER BY sortval ASC LIMIT 0, 10

If I change the count value to 20 for example, that is shown in the resulting database query.

Duncan Revell

Duncan Revell 78 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

1) default collection template that includes categories tags causes error

Yes, we've got that one logged, thanks.

2) the response is being paginated

Sorry, I don't understand. Did you want it not to be paginated?

Duncan Revell

Duncan Revell 78 points
Registered Developer

Sorry, I don't understand. Did you want it not to be paginated?

I'm using a standard $Collection->query like so (the template call is to stop the error mentioned above):

$Set->add_items($Collection->query(['template'=>'players/_fullname.html',]));

I notice that the query method sets 'paginate' => false as a default, so no, I'm not expecting it to be paginated.

As it is now, the response lines (as shown above) are telling me that paging is false and there are 10 players on 1 page. This is incorrect - there are over 300 players in the database. If I was consuming the api, I would be given false information.

If I set 'paginate'=>true, then the correct information is displayed in the response - 336 players, 34 pages etc.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I see, we'll take a look.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think these should be fixed for 3.0.13.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Thanks Drew - that seems to be working as expected.

For info, using $Collection->query() with no arguments results in the following error:

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function PerchAPI_ContentCollection::query(), 0 passed in /var/www/rugbyheritage/cms/templates/api/players.php on line 10 and exactly 1 expected in /var/www/rugbyheritage/cms/core/lib/api/PerchAPI_ContentCollection.class.php:12

Using it with an empty array is fine $Collection->query([]) - not necessarily an issue for me, but I don't know if it will confuse others...?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you probably always want to pass options to it, otherwise you're relying on defaults, which could change in the future.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Yes, that certainly makes sense. Thanks again.