Using an external API with dynamic pages

Hi all!

I’ve made a website - www . covidtravelchecker . com

It uses a data-set and dynamic pages to display information about countries.

at the moment for COVID cases per country I am just updating in excel, then uploading to the wix dataset.

I’d like to automatically populate COVID cases using this API. https : //documenter.getpostman . com/view/10808728/SzS8rjbc?version=latest#63fda84a-6b43-4506-9cc7-2172561d5c16

more specifically for e.g. south africa - https : //api.covid19api . com/live/country/south-africa/status/confirmed

Is there a way to include the API url for each country in the data set and then write some code to display the cases for each country on my dynamic page?

Please let me know!

1 Like

bump

Also interested in this. I wish to create dynamic pages from data from an external rest API.

Interested in this too!

Interested in this too!

Did you ever figure it out? I’m trying to decide right now If I can use Wix as a front end for an API and building.

Hi Justin.
Yes, I was able to make it work for me perfectly.
The issue I had initially was that the database collection needed to be populated into a sandbox, then the sandbox promoted to live. This “promotion” step is no longer an issue as the Wix team has eliminated it.

Further…

The high-level process I use is as follows:

  1. On the site’s home page, there is a call (via backend code) to the remote API to fetch all of the relevant data from the external source. I gather the bits of information that I need to begin to build a dynamic page with an unknown number of elements.

  2. I check to see if the incoming data is newer (with an embeded date stamp in the incoming data) than what I have and if so, I update the record in the collection

  3. Now that I have the record “locally” I can do whatever I want with it including fetching more data via the API using the key field in the data.

  4. When a user selects one of the elements on the dynamic page, I again call the API to get additional details, triggering a new dynamic page.

The .jsw file in the backend code is like this:

import { getJSON } from ‘wix-fetch’ ;

// import API key from Wix-Secrets container
import { getSecret } from ‘wix-secrets-backend’ ;

export async function getListingsInfo ( LStatus ) {
const url = ‘https://api.XXX.com/search?&key=’ ;
const key = await getSecret ( “Secret_API_Key” );
let fullUrl = url + key + LStatus ;

const  jsondata  =  **await**  getJSON ( fullUrl , { "mode" :  "cors" ,  "cache" :  "reload" });  
    **return** ( jsondata ); 

}

When I call getListingsInfo from the front-end, it returns the required JSON data.

Super helpful thank you. I wonder if it is possible to create a Wix dynamic page based on data that is not held in a wix data collection. For instance, If I had a listing page, of a hundred event opportunities, each with a unique ID that came from a third-party API, could I somehow use that to create a Wix dynamic page?

I believe the answer is no.

It may be possible to include a parameter within a URL that is read by the third party API to produce a single event opportunity’s details.

Almost like turning Wix into a single page web app.

You are welcome Jay.

All of the data from the API call is available in the JSON data “jsondata” that is returned to the front-end in my code snippet. I don’t see any reason why you couldn’t select from that data, to create a dynamic page using any data you wish.

More specifically, my site (ssys.ca) fetches boat listing data from a central location. It is the back-end of the “yachtworld” site where customers can search for boats for sale. Brokers in my brokerage firm add vessel details to this back-end to provide access to would-be purchasers searching on Yachtworld.com.

The API that I use comes from this back-end service so that I can dynamically construct our specific site (ssys.ca) using only data that is current (vessels from our brokerage currently available for sale). Via the API, I fetch only “available” vessel listing data to display current vessels for sale. When a user selects a vessel to find out more about it, I call the API again requesting only that vessel’s data. When one of our brokers updates the data in the back-end, it is updated the next time someone visits our site.

I only use the database to “fetch locally” if there are no changes to a particular vessel in an effort to make the performance as good as possible. Linking dynamic components on a dynamic page seems also to be a bit easier if it is linked to a collection (but is not a requirement).

I hope this helps.

Derek

It would be putting a significant amount of code base into Wix with no way to connect it to GitHub in a standard way.

And God forbid if what I’m working on actually becomes popular, I would not have full control of web server resource allocation and load balancing.

I had also thought using auth.0 to align users from my API with Wix users (enabling auto membership in Wix upon user creation) such that there (effectively) would be only one role for Wix users.

But all of this seems a bit too risky and a lot of extra effort for some widgets and a great wysiwyg HTML editor.

Understood. Good luck with your project Jay.

That’s odd It looks like the entire top half of my reply was dropped. What I had said at the top was…

Thank you again Derek that was very helpful. I had been contemplating using Wix as a front end to my API but for many reasons I think that might be a bad long-term approach… It’s not wix’s fault… It just wouldn’t be a typical use case for Wix. I’m going to have to use angular.

I really do enjoy not having to worry about web servers and the ease of adding Wix features tools and widgets. Unfortunately it just wasn’t meant to be. But the information you provide it may be helpful for other Wix sites that I manage.

My previous post got truncated for some reason… see my post below. And thanks again

Too funny. my pleasure Jay.

Yes, I hope others may find some of this useful. I know I spent days working through some of my issues and really found this forum helpful In many cases.

Hi Derek,

Me again. I was curious to know… how far down the Wix rabbit hole have you gone in the past? For instance, have you ever created tables (i.e. reports) that display data by “joining” two (or more) collections? But wait! Before you answer there is a caveat: the “join” is not on a “title” column or even a field that could be set-up (out of the box) to be a “reference” field in the corresponding collection. Thank you in advance for your response. To know if someone has ever done this will be helpful.

Despite Wix not being a proper long-term solution for me, I will be using Wix for a pilot program to help local high school students identify, sign-up, and log hours related to community service activities/opportunities.

Thank you again.

Hello Jay.

No. I haven’t needed or tried anything like that. Sounds interesting though and I imagine it would be doable. It seems to me that Wix is pretty flexible and powerful.