|
| 1 | +--- |
| 2 | +title: Azure Functions External Table binding (Preview) | Microsoft Docs |
| 3 | +description: Using External Table bindings in Azure Functions |
| 4 | +services: functions |
| 5 | +documentationcenter: '' |
| 6 | +author: alexkarcher-msft |
| 7 | +manager: erikre |
| 8 | +editor: '' |
| 9 | + |
| 10 | +ms.assetid: |
| 11 | +ms.service: functions |
| 12 | +ms.workload: na |
| 13 | +ms.tgt_pltfrm: na |
| 14 | +ms.devlang: multiple |
| 15 | +ms.topic: article |
| 16 | +ms.date: 04/12/2017 |
| 17 | +ms.author: alkarche |
| 18 | + |
| 19 | +--- |
| 20 | +# Azure Functions External Table binding (Preview) |
| 21 | +This article shows how to manipulate tabular data on SaaS providers (e.g. Sharepoint, Dynamics) within your function with built-in bindings. Azure Functions supports input, and output bindings for external tables. |
| 22 | + |
| 23 | +[!INCLUDE [intro](../../includes/functions-bindings-intro.md)] |
| 24 | + |
| 25 | +## API Connections |
| 26 | + |
| 27 | +Table bindings leverage external API connections to authenticate with 3rd party SaaS providers. |
| 28 | + |
| 29 | +When assigning a binding you can either create a new API connection or use an existing API connection within the same resource group |
| 30 | + |
| 31 | +### Supported API Connections (Table)s |
| 32 | + |
| 33 | +|Connector|Trigger|Input|Output| |
| 34 | +|:-----|:---:|:---:|:---:| |
| 35 | +|[DB2](https://docs.microsoft.com/azure/connectors/connectors-create-api-db2)||x|x |
| 36 | +|[Dynamics 365 for Operations](https://ax.help.dynamics.com/wiki/install-and-configure-dynamics-365-for-operations-warehousing/)||x|x |
| 37 | +|[Dynamics 365](https://docs.microsoft.com/azure/connectors/connectors-create-api-crmonline)||x|x |
| 38 | +|[Dynamics NAV](https://msdn.microsoft.com/library/gg481835.aspx)||x|x |
| 39 | +|[Google Sheets](https://docs.microsoft.com/azure/connectors/connectors-create-api-googledrive)||x|x |
| 40 | +|[Informix](https://docs.microsoft.com/azure/connectors/connectors-create-api-informix)||x|x |
| 41 | +|[Dynamics 365 for Financials](https://docs.microsoft.com/azure/connectors/connectors-create-api-crmonline)||x|x |
| 42 | +|[MySQL](https://docs.microsoft.com/azure/store-php-create-mysql-database)||x|x |
| 43 | +|[Oracle Database](https://docs.microsoft.com/azure/connectors/connectors-create-api-oracledatabase)||x|x |
| 44 | +|[Common Data Service](https://docs.microsoft.com/common-data-service/entity-reference/introduction)||x|x |
| 45 | +|[Salesforce](https://docs.microsoft.com/azure/connectors/connectors-create-api-salesforce)||x|x |
| 46 | +|[SharePoint](https://docs.microsoft.com/azure/connectors/connectors-create-api-sharepointonline)||x|x |
| 47 | +|[SQL Server](https://docs.microsoft.com/azure/connectors/connectors-create-api-sqlazure)||x|x |
| 48 | +|[Teradata](http://www.teradata.com/products-and-services/azure/products/)||x|x |
| 49 | +|UserVoice||x|x |
| 50 | +|Zendesk||x|x |
| 51 | + |
| 52 | + |
| 53 | +> [!NOTE] |
| 54 | +> External Table connections can also be used in [Azure Logic Apps](https://docs.microsoft.com/azure/connectors/apis-list) |
| 55 | +
|
| 56 | +### Creating an API connection: step by step |
| 57 | + |
| 58 | +1. Create a function > custom function |
| 59 | + |
| 60 | +1. Scenario `Experimental` > `ExternalTable-CSharp` template > Create a new `External Table connection` |
| 61 | + |
| 62 | +1. Choose your SaaS provider > choose/create a connection |
| 63 | + |
| 64 | +1. Select your API connection > create the function |
| 65 | + |
| 66 | +1. Select `Integrate` > `External Table` |
| 67 | + 1. Configure the connection to use your target table. These settings will very between SaaS providers. They are outline below in [data source settings](#datasourcesettings) |
| 68 | + |
| 69 | + |
| 70 | +## Usage |
| 71 | + |
| 72 | +This example connects to a table named "Contact" with Id, LastName, and FirstName columns. The code lists the Contact entities in the table and logs the first and last names. |
| 73 | + |
| 74 | +### Bindings |
| 75 | +```json |
| 76 | +{ |
| 77 | + "bindings": [ |
| 78 | + { |
| 79 | + "type": "manualTrigger", |
| 80 | + "direction": "in", |
| 81 | + "name": "input" |
| 82 | + }, |
| 83 | + { |
| 84 | + "type": "apiHubTable", |
| 85 | + "direction": "in", |
| 86 | + "name": "table", |
| 87 | + "connection": "ConnectionAppSettingsKey", |
| 88 | + "dataSetName": "default", |
| 89 | + "tableName": "Contact", |
| 90 | + "entityId": "", |
| 91 | + } |
| 92 | + ], |
| 93 | + "disabled": false |
| 94 | +} |
| 95 | +``` |
| 96 | +`entityId` must be empty for table bindings. |
| 97 | + |
| 98 | +`ConnectionAppSettingsKey` identifies the app setting that stores the API connection string. The app setting is created automatically when you add an API connection in the integrate UI. |
| 99 | + |
| 100 | +A tabular connector provides data sets, and each data set contains tables. The name of the default data set is “default.” The titles for a dataset and a table in various SaaS providers are listed below: |
| 101 | + |
| 102 | +|Connector|Dataset|Table| |
| 103 | +|:-----|:---|:---| |
| 104 | +|**SharePoint**|Site|SharePoint List |
| 105 | +|**SQL**|Database|Table |
| 106 | +|**Google Sheet**|Spreadsheet|Worksheet |
| 107 | +|**Excel**|Excel file|Sheet |
| 108 | + |
| 109 | +<!-- |
| 110 | +See the language-specific sample that copies the input file to the output file. |
| 111 | +
|
| 112 | +* [C#](#incsharp) |
| 113 | +* [Node.js](#innodejs) |
| 114 | +
|
| 115 | +--> |
| 116 | +<a name="incsharp"></a> |
| 117 | + |
| 118 | +### Usage in C# # |
| 119 | + |
| 120 | +```cs |
| 121 | +#r "Microsoft.Azure.ApiHub.Sdk" |
| 122 | +#r "Newtonsoft.Json" |
| 123 | + |
| 124 | +using System; |
| 125 | +using Microsoft.Azure.ApiHub; |
| 126 | + |
| 127 | +//Variable name must match column type |
| 128 | +//Variable type is dynamically bound to the incoming data |
| 129 | +public class Contact |
| 130 | +{ |
| 131 | + public string Id { get; set; } |
| 132 | + public string LastName { get; set; } |
| 133 | + public string FirstName { get; set; } |
| 134 | +} |
| 135 | + |
| 136 | +public static async Task Run(string input, ITable<Contact> table, TraceWriter log) |
| 137 | +{ |
| 138 | + //Iterate over every value in the source table |
| 139 | + ContinuationToken continuationToken = null; |
| 140 | + do |
| 141 | + { |
| 142 | + //retreive table values |
| 143 | + var contactsSegment = await table.ListEntitiesAsync( |
| 144 | + continuationToken: continuationToken); |
| 145 | + |
| 146 | + foreach (var contact in contactsSegment.Items) |
| 147 | + { |
| 148 | + log.Info(string.Format("{0} {1}", contact.FirstName, contact.LastName)); |
| 149 | + } |
| 150 | + |
| 151 | + continuationToken = contactsSegment.ContinuationToken; |
| 152 | + } |
| 153 | + while (continuationToken != null); |
| 154 | +} |
| 155 | +``` |
| 156 | + |
| 157 | +<!-- |
| 158 | +<a name="innodejs"></a> |
| 159 | +
|
| 160 | +### Usage in Node.js |
| 161 | +
|
| 162 | +```javascript |
| 163 | +module.exports = function(context) { |
| 164 | + context.log('Node.js Queue trigger function processed', context.bindings.myQueueItem); |
| 165 | + context.bindings.myOutputFile = context.bindings.myInputFile; |
| 166 | + context.done(); |
| 167 | +}; |
| 168 | +``` |
| 169 | +--> |
| 170 | +<a name="datasourcesettings"></a> |
| 171 | +## Data Source Settings |
| 172 | + |
| 173 | +### SQL Server |
| 174 | + |
| 175 | +The script to create and populate the Contact table is below. dataSetName is “default.” |
| 176 | + |
| 177 | +```sql |
| 178 | +CREATE TABLE Contact |
| 179 | +( |
| 180 | + Id int NOT NULL, |
| 181 | + LastName varchar(20) NOT NULL, |
| 182 | + FirstName varchar(20) NOT NULL, |
| 183 | + CONSTRAINT PK_Contact_Id PRIMARY KEY (Id) |
| 184 | +) |
| 185 | +GO |
| 186 | +INSERT INTO Contact(Id, LastName, FirstName) |
| 187 | + VALUES (1, 'Bitt', 'Prad') |
| 188 | +GO |
| 189 | +INSERT INTO Contact(Id, LastName, FirstName) |
| 190 | + VALUES (2, 'Glooney', 'Ceorge') |
| 191 | +GO |
| 192 | +``` |
| 193 | + |
| 194 | +### Google Sheets |
| 195 | +In Google Docs, create a spreadsheet with a worksheet named `Contact`. The connector cannot use the spreadsheet display name. The internal name (in bold) needs to be used as dataSetName, for example: `docs.google.com/spreadsheets/d/`**`1UIz545JF_cx6Chm_5HpSPVOenU4DZh4bDxbFgJOSMz0`** |
| 196 | +Add the column names `Id`, `LastName`, `FirstName` to the first row, then populate data on subsequent rows. |
| 197 | + |
| 198 | +### Salesforce |
| 199 | +dataSetName is “default.” |
| 200 | + |
| 201 | +## Next steps |
| 202 | +[!INCLUDE [next steps](../../includes/functions-bindings-next-steps.md)] |
0 commit comments