I have been googling to find the tutorial and material to find the easy way to learn the process to get the data to collection from my own end point.
My api end point is protected with auth. I see some docs that I need to set up the code for backend to api request to get the data from the data source. It looks fine and easy. But I dont know how to push that data (response body) to the data collection so that I can utilize the collection for fronend.
Apprecaite for guide.
See this example to see how to expose and communicate with your own API:
Expose and Access Site APIs
Use MyApi and MyApiClient to expose and access external APIs.
Thank you Yesrael. However, is there any other resource addressing to my exact issue. What I would like to achieve.
- I have full set of API , get, update and delete, add.
- Retrieve data from this API endpoint and push to Wix.com
3) Once the api is called (upon loading page) then data will be stored into Database Collection.
4) Refer to this collection, make LIST or table view as element within a page.
Appreciate for your further help.
You will need to get accustomed with the Corvid API, namely Wix Data to insert your data into a collection and the Wix Fetch to fetch data from the external API.
Once you retrieve your data from the external API you will need to study the response in order to store it in the database. For example if I get the below response
var response = {
name: "shan",
role: "Corvid Master",
email: "shan@xxxxx.com"
}
Then in order to store this data I will use the below code:
let toInsert = {
moderatorName: response.name,
moderatorRole: response.role,
moderatorEmail: response.email
}
wixData.insert("collectionName", toInsert);
Note that the field keys (moderatorName, moderatorRole, moderatorEmail) need to be created in the database.
@shantanukumar847 Thank you very much! Actually my API response body is array of objects. In that case, we need to do for loop/for each, in that case, how sample code is going to be looking like?
Another question is we dont need to configulate anything on collection to push the data in it? I assumed we need to set the column date name and types should be preset before we push objects into it. We dont need? Sorry, i m pretty new to Corvid.
@koichitsuji0511 A sample code for the for each function looks like this:
items.forEach( (item, i) => {
//item
});
You need to create the fields in the database.
@koichitsuji0511 Since you are new to Corvid, check out the Corvid Resources page where you can find tutorials, examples, and articles on getting the most out of Corvid. As questions or difficulties arise, we are here to help.
You may want to check out the WixArena - it’s a hub where you can look for Corvid (and other) experts for hire.
@shantanukumar847 thank you for your advice. I managed to get data to data collection from my api end point.
now I want to extend the feature to do other operation, add, update and delete using web hooks
What I mean all the action will be triggered by event listeners put on this data collection. If new row is added to this table then trigger api POST to add data to original data source through api. Same for update and delete as well.
At the end I want to make sure the original external data source is always having a kinda I’d copy or replica as data collection in wix .
All in all I wish to establish full crud Operaion using api webhooks
I spent few hours over the Corvid docs and read through the part of external database connection . Adapter and SPI are mentioned there but none of them clearly understandable to me. I do understand API in general , but those docs did not help me to set up communitions between wix site and my data source to do CRUD operation.
in The meantime my data is sitting in ms sql, but I do have full set of rest api for this dB.
koichi