Play with your data with a custom API

Article by Mohand Bencherif - 09 Apr 2020 - 4 minute read

How to play with your data with a custom API

Build your online marketplace today!

Benefit from a 7-day free trial, with no obligation or payment card

Play with your data with a custom API :

There is many way to recover data on your marketplace, one of them is to use Bridge

Bridge is a very easy and efficient tool to create an API REST from an Excel file. Just go to Bridge website, click on “Create my Bridge API”.

 

                    

Once you create an account and answered questions, click on “Create a new API”.  

Once you have named and described your API, click on “Add a new spreadsheet 

 

 

 

Here you need to select your file, xls, xlsx or csv. You can get theses files with Kreezalid, when you export your data. You can export your users, your listings, your listings categories, your orders, your blog posts... 

 

 

 

When you click on export you can choose your file type, csv or xls. They are compatible with Bridge. 

On Bridge, sometimes, when you choose a file, you can have an error message : 

 

              

 

To resolve this problem, you just need to open your file with Excel or Openoffice, and save it with xls or csv extension. 

Now, that your file is uploaded, we’ll need to look at the documentation 

 

                                                

Now your API is ready to use. We will take a blog posts export for example on this article, note that this is valid for all your exports. 

This is our object : 

 

 

We can see that our API returns JSON content. 

That you can get with :

     -GET https://bridge.buddyweb.fr/api/yourapi/yourobject. 

With this, you will have a json array which contain all of you objects, you can get a specific object with :

     -GET https://bridge.buddyweb.fr/api/yourapi/yourobject/{id}. 

You can find all these informations on the documentation of your API. 

 

Now let’s see how to get your data on a page.
 

From your admin dashboard, go to “themes” and “customize js” to edit your javascript code.

There is an exemple of Javascript code that you can use to get your data : 
 

var request = new XMLHttpRequest();
request.addEventListener('load', onLoad);
request.open('GET', 'https://bridge.buddyweb.fr/api/testblogposts/posts');
request.send();

function onLoad(){
var posts = JSON.parse(request.responseText);
$.each(posts, function(index) {
console.log(posts[index])
document.getElementById("testblog").innerHTML += '<p>'+JSON.stringify(posts[idx])+'</p>'
});
}


This code make a call to your API, and recover data of all the posts of our file. 
onLoad() function returns a JSON array, which we will parse in a loop.

Mohand Bencherif
About Mohand Bencherif

Co-founder & CTO at Kreezalid

Web developer and then e-commerce consultant, I started to work with marketplaces actors since 2013. I gladly share my experiments and the good practices that I discover.