Jump to content

Easy JSON Feed - without module


wbmnfktr
 Share

Recommended Posts

$restaurants = $pages->findRaw("template=restaurant", ['id', 'title', 'modified']);
$json = json_encode(['restaurants' => array_values($restaurants)]);

Moved this from here - to keep the other thread clean:

So... yeah that little script does a really good job.
While I read about findRaw() somewhere I never really cared somehow. Maybe because I haven't looked that deep into it.

It does an amazing job but for a ready to use JSON feed in an external site/app/ssg parts are missing - for me.
Text and textarea fields are fine and easy to use somewhere else.

PageReferences are slightly different and need a slightly different subfield request with, otherwise you would just receive the IDs:
'myPageReferenceFieldMultiple.title'

"myPageReferenceFieldMultiple": {
  "7009": {
  "title": "Voucher"
  },
  "7010": {
  "title": "Dinner"
  },
  "7011": {
  "title": "Outdoor"
  },
  "7012": {
  "title": "Vegan offers"
  },
  "7013": {
  "title": "Take away"
  },
  "8574": {
  "title": "Special offers"
  }
},

Image fields really only have the raw data. No url, no image details, nothing.

"myImageFieldSingle": [
  {
    "data": "logo.png",
    "sort": "0",
    "description": "",
    "modified": "2020-04-16 18:59:33",
    "created": "2020-04-16 18:59:33",
    "filedata": "",
    "filesize": null,
    "created_users_id": "0",
    "modified_users_id": "0",
    "width": null,
    "height": null,
    "ratio": null
  }
],

And repeater matrix fields are yet another animal. Similar to repeater fields but more complicated to get each and every matrix entry and its details.

"myRepeaterMatrixField": {
  "data": "8577,7060,7360,6443,6415,6414",
  "count": "6",
  "parent_id": "6399"
}

 

Amazing... so far.

Ping at @bernhard @kongondo

  • Like 1
Link to comment
Share on other sites

1 hour ago, wbmnfktr said:

PageReferences are slightly different and need a slightly different subfield request with, otherwise you would just receive the IDs:
'myPageReferenceFieldMultiple.title'

Yes. There are these alternatives though:

Quote

// You can also use this format below to get multiple subfields from one field: $a = $pages->findRaw("template=blog", [ "title", "categories" => [ "id", "title" ] ]);

☝️this has never worked for me though. Will at best return an empty array and at worst throw a SQL error.

1 hour ago, wbmnfktr said:

Image fields really only have the raw data. No url, no image details, nothing.

Works fine for me, except for URL. I get  ratio, width, etc.

 

https://processwire.com/api/ref/pages/find-raw/

Edited by kongondo
Link to comment
Share on other sites

18 minutes ago, kongondo said:

☝️this has never worked for me though. Will at best return an empty array and at worst throw a SQL error.

It's the same here.

18 minutes ago, kongondo said:

Works fine for me, except for URL. I get  ratio, width, etc.

Oh... that's interesting. I tried my query on all of my pages and... some now return details, yet I don't know what's happening. It didn't bother me in the past so I just might ignore it for the moment.

 

20 minutes ago, kongondo said:

That's were I was looking right now.

  • Like 1
Link to comment
Share on other sites

Well... what you are discovering is exactly why I built RockFinder. The first version was built before findRaw existed but I'm still using the current version RockFinder3 for RockGrid because it does all the things you mentioned properly with an easy to use syntax.

Link to comment
Share on other sites

So maybe I have to play with RockFinder3 a bit even before trying AppApi.

To be honest I would never ever have thought about using it just because it feels way overhead for "just a JSON feed".

So... I will cherry-pick in that docs and maybe find a way to get the results I need.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...