The Situation
I'm working with an external API that gives me an XML feed of items and categories. The API works with category IDs and returns items in that category. What I'm trying to do is the following:
- Make an endpoint
products
which shows all the available categories:domain.com/products/
- Make a dynamic endpoint that passes the category ID via query string
?custom_category=2
and rewrites it into a pretty permalink likedomain.com/products/categoryname/
- I don't know the category names so I need to ask the API the category name by the given ID. - Finally, in a similar fashion as above I need to take a given item ID via query string
item_id=17
and rewrite it into a pretty permalink of which I'm not picky:domain.com/products/productname/
ordomain.com/products/categoryname/productname/
- I don't know the item names so I need to ask the API the item name by the given ID.
I have to use IDs in links because the API is old and doesn't understand slugs ( so I can't pass my API a slug and expect results I need to pass an ID of some kind ) but I was hoping to grab the ID from the query string, hit the API to get the name, make it URL friendly and put it into the URL.