Search code examples
google-app-maker

Load Data from API into App Maker


I have data returned from API call, which is an array. I want to create a list in App Maker to display the items in the array. I have already put my API calling in sever script. How can I load the data into list widget?


Solution

  • You can transform response from your API into Calculated Model's records and then load and bind them on UI:

    // Server script
    function getCaluculatedModelRecords() {
      var apiObjects = getMyMagicObjectsFromApi();
    
      return apiObjects.map(function(apiObj) {
        var record = app.models.MyCalculatedModel.newRecord();
    
        record.Field1 = apiObj.field1;
        record.Field2 = apiObj.field2;
        record.Field3 = apiObj.field3;
        ...
    
        return record;
      });
    }
    

    Maybe this sample will be somehow helpful as well: https://developers.google.com/appmaker/samples/calculated-model/