Skip to the content.

title: “Badge Function (GetScanCount)” layout: default permalink: /docs/badge-function/ —

Azure Function: GetScanCount (NFC Scan Badge)

This Azure Function powers the “Total NFC Scans” badge shown in the README:

Endpoint Badge

It queries Application Insights using the App Insights REST API (read-only) and returns shields.io compatible JSON.

Why a separate function?

Required App Settings

Name Required Description
APP_INSIGHTS_APP_ID Yes Application Insights application ID (from the resource used by the mobile app).
APP_INSIGHTS_API_KEY Yes API key with read permissions for the App Insights resource (create via Azure Portal > API Access).

Optional App Settings

Name Default Description
APP_INSIGHTS_KQL_QUERY customEvents \| count Full KQL query that must return a single numeric value in the first cell of the first row. You can embed constants (baselines), filters, time ranges, etc. directly in the query. Example: print 1234 + toscalar(customEvents \| count).

Error / Configuration States

The endpoint always returns HTTP 200 + valid shields.io JSON so the badge renders reliably in GitHub READMEs.

Visible message values in the badge:

Logs in the Function App will contain details for troubleshooting.

Deployment Notes

Local Development

  1. Copy src/DeviceFX.Function/local.settings.json and fill real values (or keep placeholders to test the “unconfigured” path).
  2. Run the function project (F5 in VS Code or func start from the src/DeviceFX.Function dir after dotnet build).
  3. Hit http://localhost:PORT/api/GetScanCount (port shown in launch profile or output).

Updating the Badge Query Without Code Changes

Update the APP_INSIGHTS_KQL_QUERY Application Setting. The query itself can include any baseline or calculation (e.g. print 1234 + toscalar(customEvents | count)). No code change or mobile app rebuild is required.

References