johnwargo
johnwargo

Reputation: 797

Azure Functions read Azure Mobile App Easy table data

I'm trying to figure out how to setup an input binding to an Azure Function that enables it to read all of the data in an Azure Mobile App Easy tables table. I've been searching for hours and reading every bit of documentation that I can find.

The Azure Functions binding docs at https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings indicate that I can setup a binding for Mobile Apps - the docs says this is for accessing tables, I hope it means Easy tables because that is, I think, the only kind of tables available in a mobile app (or am I mistaken?). There's even a helper option when setting up the binding in the Integrations section of the Functions editor. However, when you setup the binding, the Record ID field is required, but I don't want to specify a record ID, I want the function to be able to read all of the data in the table. How do I do this?

Ultimately, what I want to be able to do is trigger the function whenever data in the table is updated (add, update, delete). When the function executes, I want to read all of the data and do something with it. I can't find a trigger option that covers this, so I think I'm going to have to just make this a scheduled function - is there a better way?

Here's the binding:

{
  "type": "mobileTable",
  "name": "inputRecord",
  "tableName": "Alerts",
  "id": "{itemId}",
  "connection": "APP_URL",
  "direction": "in"
}

It's the id property in the binding that's not needed in my case, but required. What do I put there to make it work?

Upvotes: 1

Views: 449

Answers (1)

Paul Batum
Paul Batum

Reputation: 8415

There is no built in trigger type for Easy Tables yet. But you can achieve this scenario using the recently added webhooks feature of Mobile Apps Easy Tables. Make a HTTP triggered function and configure the webhook to call the function. If you need your function to update the state of the data in easy tables, you can use an output binding to do that.

If you need richer interaction with the data from the function then you'll want to look at referencing the Mobile Apps client SDK NuGet package and use the MobileServiceClient to read the data. Here's an example:

project.json:

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.Azure.Mobile.Client": "3.0.3"
      }
    }
  }
}

run.csx:

using System.Net;
using Microsoft.WindowsAzure.MobileServices;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    MobileServiceClient client = new MobileServiceClient("https://mymobileappssite.azurewebsites.net");
    var results = await client.GetTable("todoitem").ReadAsync("");
    log.Info($"Got {results.Count()} record(s).");;

    return req.CreateResponse(HttpStatusCode.OK, "Hi");    
}

Upvotes: 2

Related Questions