Bulk Add Records from API (no documentation)

Options
eriks
eriks Member
edited September 2023 in ? Working with APIs

Hi everyone,

Instead of me spending another 6 hours trying to be a detective, I thought I would ask here instead :)

I'm basically trying to create a table with all the countries rom the restcountries.com api. I need this in a table that stays up to date, and the table will link with several important other tables in my DB. Im working on a language application, so this is key for me to nail.

I had initially looked at old documentaiton and youtube videos explaining how to use loop to iterate through items, however, I noticed that there was a new functionality called "Add bulk Records". Only issue is that it's one video on a few minutes explaining one use case that does not fit mine.

Has anyone used this "Add Bulk Records" and knows how I should set it up with my API so my table stays up to date with the API (or whatever is best practise).

Please help me save another 6 hours digging the internet, hehe

Comments

  • eriks
    eriks Member
    Options

    Seems like no one in the community can help with this, maybe someone from the Xano team?:)

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Hi,

    So in bulk add, what you need to do is provide a list of json objects that's reflect the structure of the table you want to add records in. If you can show more about how your objects from api and records in table looks like I will be able to help more.

  • eriks
    eriks Member
    Options

    Here is the schema from the table:


    { "common": "", "cca2": ""}

    Here is what the API returns:
    {
    data: {
    request: {
    url: https://restcountries.com/v3.1/all?fields=name,cca2,
    method: GET,
    headers: [
    GET /v3.1/all?fields=name,cca2 HTTP/1.1,
    Host: restcountries.com,
    Accept-Encoding: gzip, deflate,
    Accept: application/json],
    params: },
    response: {
    headers: [
    HTTP/1.1 200 OK,
    Date: Wed, 27 Sep 2023 15:26:02 GMT,
    Server: Apache/2.4.38 (Debian),
    Cache-Control: public, immutable, max-age=31556926,
    content-type: application/json,
    content-encoding: gzip,
    content-length: 11126],
    result: [
    {
    name: {
    common: French Polynesia,
    official: French Polynesia,
    nativeName: {
    fra: {
    official: Polynésie française,
    common: Polynésie française}}},
    cca2: PF},
    {
    name: {
    common: Saint Martin,
    official: Saint Martin,
    nativeName: {
    fra: {
    official: Saint-Martin,
    common: Saint-Martin}}},
    cca2: MF},
    {
    name: {
    common: Venezuela,
    official: Bolivarian Republic of Venezuela,
    nativeName: {
    spa: {
    official: República Bolivariana de Venezuela,
    common: Venezuela}}},
    cca2: VE},
    {
    name: {
    common: Réunion,
    official: Réunion Island,
    nativeName: {
    fra: {
    official: Ile de la Réunion,
    common: La Réunion}}},
    cca2: RE},
    {
    name: {
    common: El Salvador,
    official: Republic of El Salvador,
    nativeName: {
    spa: {
    official: República de El Salvador,
    common: El Salvador}}},
    cca2: SV}

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Ok, so if your table in Xano reflect that json structure from API then your json for bulk should look like more or less like below, of course with the number of elements required by you. Might be the case that you need to modify it a bit to fit your table record.

    [{
    name: {
    common: French Polynesia,
    official: French Polynesia,
    nativeName: {
    fra: {
    official: Polynésie française,
    common: Polynésie française}}},
    cca2: PF},
    {
    name: {
    common: Saint Martin,
    official: Saint Martin,
    nativeName: {
    fra: {
    official: Saint-Martin,
    common: Saint-Martin}}},
    cca2: MF}]