Importing Data from an External API

Knowledge level: Complete noob (no dev experience at all)

Backendless Version: Online

Client SDK (REST) (I think? I’m just calling an external API, the data returned is JSON)

Application ID D15738AC-BE6F-08DC-FF37-FD69750C0200

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. Call external API.
  2. Bulk update database with the returned result of the API Call.
  3. The API call contains what I believe are called nested groups, so I need to build the logic to identify these items as well.
  4. Some of the data will be relational so I will need to push these to separate tables and link with a relational object data type.

Actual Behavior

  1. API call is successful and I receive all of the information that I want in the response. I achieved this by creating codeless logic in the Business Logic section: Codeless logic - HTTP Request & Response Received.
  2. Now I’m stuck as to how I can correctly format the response so that I’m able to save this into the database.

Do I need to format these items into a list, then bulk update the database? (I tried some variants of this but I couldn’t get it working: https://i.imgur.com/3QUwSKq.png )

I’ve messed around with a similar setup to this training video:

What I don’t know is how to have the returned API response become the Data of Body and how to correctly format the method so that it matches the response exactly.

Method setup: https://i.imgur.com/MbpiNAm.png
https://i.imgur.com/DjKsiRj.png

Body Schema that is returned - it doesn’t quite match to format of the API response

{
    "getProperties": [
        "string"
    ],
    "country": "string",
    "address": "string",
    "city": "string",
    "propId": "string",
    "latitude": "string",
    "postcode": 0,
    "ownerId": 0,
    "propTypeId": 0,
    "roomTypes": [
        "string"
    ],
    "name": "string",
    "currency": "string",
    "state": "string",
    "longitude": "string"
}

Sample of the returned items (2 complete responses of the data that I need to capture inside of my Property & Room Tables in my database)

{
    "getProperties": [
        {
            "country": "AU",
            "address": "36 Lockhart Avenue ",
            "city": "Mollymook Beach",
            "propId": "134988",
            "latitude": "-35.3282130",
            "postcode": "2539",
            "ownerId": "74671",
            "propTypeId": "17",
            "roomTypes": [
                {
                    "unitAllocationPerGuest": "0",
                    "maxAdult": "0",
                    "unitNames": "",
                    "qty": "1",
                    "minPrice": "0.00",
                    "name": "Avenue 36",
                    "maxPeople": "8",
                    "roomId": "301423",
                    "maxChildren": "0"
                }
            ],
            "name": "Avenue 36",
            "currency": "AUD",
            "state": "NSW",
            "longitude": "150.4738920"
        },
        {
            "country": "AU",
            "address": "45 George Avenue",
            "city": "Kings Point",
            "propId": "134989",
            "latitude": "-35.3687670",
            "postcode": "2539",
            "ownerId": "74671",
            "propTypeId": "17",
            "roomTypes": [
                {
                    "unitAllocationPerGuest": "0",
                    "maxAdult": "0",
                    "unitNames": "",
                    "qty": "1",
                    "minPrice": "0.00",
                    "name": "George's Hideaway",
                    "maxPeople": "8",
                    "roomId": "301424",
                    "maxChildren": "0"
                }
            ],
            "name": "George's Hideaway",
            "currency": "AUD",
            "state": "NSW",
            "longitude": "150.4412080"
        },

Currently I have not setup my database with the correct schema - I was looking to do this as soon as I worked out how to get the above working with some sample data first.

Any tips to point me in the right direction would be greatly appreciated :slight_smile:

Snapshot of my browser tabs trying to find a solution before I posted for help :rofl: :https://i.imgur.com/u0mdG9C.png

1 Like

Hello @Lachlan_McPherson

Do I need to format these items into a list, then bulk update the database?

Yes, but you do some mistakes.

  1. API returns your object with property getProperties what contains a list of objects.

  2. At Bulk create you use as argument object with property propName, but must use array(list)

So on the screenshot, you try to same structure as this

{
 propName: [
    {
    "getProperties": [
        { obj },
        { obj },
      ]  
    }
  ]
}

And as you see it does not look the same as what you should save.

I would recommend learning how to work with a list and an object in Сodeless. All information about it should be in Youtube playlists about Codeless and UIBuilder.

If I don’t answer your question, please let me know.

Regards, Dima