Thread tagged as: Api, Add-on-development, Field-Types

Updating Categories via API / Better solution?

Our team has a website runnning on Runway. It is for a national US restaurant chain with 400+ locations.

Currently, visitors have the ability to select their closest location and a default is automatically selected based on IP address. This location data is stored in the same database as the perch but just in a table called locations. We have a perch addon that fetches JSON data from an API and dumps these locations in a table called locations. Each location has a unique ID that never changes.

Ideally, we'd like to be able to update the perch app to be a bit better integrated into Perch so that when it dumps the locations into the table, it also creates/updates categories that can be used as fields on any type of content.

Is this feasible? Is there a better solution?

Jeremy Heilpern

Jeremy Heilpern 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

There's not an official public API for this, but the private API is pretty simple. If you don't mind keeping an eye on it across updates, it should be reasonably easy to do:

Assuming $API is an API instance, create a new category bar in the set foo with:

$Categories = new PerchCategories_Categories($API);
$NewCategory = $Categories->find_or_create('foo/bar/');
Duncan Revell

Duncan Revell 78 points
Registered Developer

Drew answered as I was typing!

Do the locations need to end up as categories?

I don't think there is a Perch public API for categories - I guess you could write something that dumps the locations into the categories table, but that probably wouldn't be a supported solution.

If all you need is to pull the locations into regions, you can write your own fieldtype that would look at the locations table and pull content into the region. I would also guess you could mimic some of the category functionality, but again it depends how far you need to go.

Thanks, guys. We were looking at categories because of the ability to create and organize sub-categories. It looks like Drew's comment should help with what were trying to do, but a new fieldtype will likely be the eventual solution we move towards, given that the client may want to update the feature in future.