David Beesley Posted July 29, 2016 Share Posted July 29, 2016 Hi All, Second time poster, so please continue to go easy on me. I have a requirement to store some minimal data from an external API within ProcessWire, alongside some page data. Lets say I want to create a page of "Offers" but my products were stored externally and exposed to me via a REST API with the endpoint /products/all (assume we are authenticated) I would like to access the API from a repeater field in ProcessWire, show a list of "ID - NAME" and then store the external ID alongside some manually inputted data. This ID could then be used at a later date for any other sort of work with the external API. What would be the best approach to create a field for this? If it is even possible? Thanks, Dave Link to comment Share on other sites More sharing options...
horst Posted July 29, 2016 Share Posted July 29, 2016 If I understand you right, you simply need to create all fields you need. (In PW, all fields are custom fields!) Put your desired fields together in a template, and use this template when importing external data into pages. imported-data: - import 1: extid = 1, text = bla, amount = 10, ... - import 2: extid = 7, text = blu, amount = 7, ... - import 3: extid = 21, text = blo, amount = 0, ... Does this help? Link to comment Share on other sites More sharing options...
David Beesley Posted July 29, 2016 Author Share Posted July 29, 2016 Kinda. I was thinking more about something that populates a field (most likely a select dropdown) from the API endpoint at the time you are editing the data. I assume I am going to have to write a module that does everything based on some kind of hook. https://processwire.com/api/modules/ Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 29, 2016 Share Posted July 29, 2016 Simply populating a select field seems like an easy idea, but you'll still store the selection in processwire, so what happens if that element won't be available anymore by your external api? ProcessWire's db will still have the selection saved until the page will be saved the next time. Also – as the select field options are generated from your api – you won't even notice, that there's still a previous state in the db when looking in the backend because that selected option is no longer part of the select field and therefore invisible. If you've that case covered it shouldn't be to hard to simply extend Fieldtype/InputfieldSelect and just add in your custom option retrieval. Link to comment Share on other sites More sharing options...
David Beesley Posted July 29, 2016 Author Share Posted July 29, 2016 In this scenario. The offers are short lived, and regularly replaced. So it hopefully shouldn't be an issue. That said, it's a valid consideration. I had considered a batch import of product data into PW via CRON. But that, I suppose, would have a similar issue if the product is removed it will be removed from PW. It's always the danger I suppose, when creating a replication of a data source. I'll take a look at creating an extension of Fieldtype/InputfieldSelect that get's its data from the API. Although perhaps an extension of a fieldtype with pagination may be a more user friendly solution when the product amounts get into the hundreds or more. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 29, 2016 Share Posted July 29, 2016 There's currently only a single type of Inputfield / Fieldtype that does support the pagination feature and that's InputfieldTable (since about a week). But the support for it is in the latest pw version, if you'd like to go for it. 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 31, 2016 Share Posted July 31, 2016 not sure if i understand you correctly david, but maybe @adrian 's batch child editor is worth a look? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now