-
- 129 Posts
Hello,
I have a customer with an external document repository, a newsletter system. I am in the process of writing a snippet that will access the external documents via their API and display them through a modx site.
It occurs to me that it would be far more convenient to import these documents, programatically, as modx resources. This way I can use all the usual snippets to display them (getResources, getPage etc) and also means the content is cached without me having to write my own caching. The documents never change once they are created, so all I need to do is get a list, compare it to what is already present, and add any new ones.
Is creating MODx resources this way a sensible approach? I haven't explored the modx api before to do this type of thing. The unique id of each document on the remote site is numeric, so I could use these as the modx resource ID which would make comparison easy.
Any pointers - if anyone has done anything similar and has examples, it would be great to see them.
-
- 24,544 Posts
You could put the external IDs in an unused text field (e.g., introtext, description). You could also store them in a TV, but having them in a standard field will make retrieval quite a bit faster and easier.
TBH, I'm not sure if you can specify the ID or not -- a quick test should tell you. If so, you could avoid collisions by adding some constant to all of them that's larger than your highest current ID (assuming that you're only doing this once).
If you can get the api returning an xml or a JSON string you can just make 1 resource and have it display the fields you need and make a list with all the other documents in order to change documents, this is just me throwing out ideas IDK what you project looks like or it's needs.
It is much easier to manage 1 resource that is dynamic than have MODX create hundreds of resources and try managing them.
Just my 2 cents.
Along with benmarte, I would be concerned if the API is going to continue to be used -- in that case, it is the source for new content, and copying data into MODX resources could be problematic in the long run.
Maybe you can write a snippet that utilizes its own cache -- i.e. it caches the data from each unique ID coming from the API. Just set it to never expire (or expire seldomly). Then you'd just have one Snippet to maintain and your site would act as a transparent window into the data in the API.