Publish an OData API
An OData API is an API Studio collection of type OData. It serves OData V4: a service
document, $metadata, and entity sets that Excel, Power BI and other OData clients read
directly.
Create the API
- Open API Studio and select New API.
- Set Type to OData.
- Under Start from, choose OData service, or From a connection to start from a table.
- Select Create API.
Design the model
The Visual view of API Studio > Design > Designer shows the OData designer.
- Namespace names the schema in
$metadata. - Entity types hold properties, each with a name, an Edm type and Nullable.
- Key marks the key properties. A key property is never nullable.
- Searchable marks the text properties that
$searchreads. - Navigation properties point to another entity type, as one item or a collection. Entity set names the set the related rows come from, and Joins on pairs a property of this type with a property of the related type.
- Entity sets publish an entity type under a name in the URL.
Fix before publishing lists what must change before the API can be served.
Choose where rows come from
Each entity set has a Rows come from setting.
| Setting | Rows |
|---|---|
| Sample rows | The sample rows saved with the API. |
| Flow | A flow you name by Project ID and Workflow ID. The flow receives the parsed query options in request.odata and returns the rows. |
| Connection object | A table on a database connection, chosen by Connection, with Database, Schema and Table. |
For a connection object, $filter, $select, $orderby, $top, $skip, $search and
$expand run in the database. Every value is sent as a query parameter. The query is read only.
An expanded set must be a table on the same connection.
What a deployed OData API answers
The service root is the API's address:
/t/<account>/<environment>/<api>/<version>/
| Request | Answer |
|---|---|
GET / | The service document, listing the entity sets. |
GET /$metadata | CSDL XML. Add $format=json or Accept: application/json for CSDL JSON. |
GET /<Set> | The rows, with @odata.context. |
GET /<Set>(<key>) | One entity by key. A composite key is written A=1,B='x'. |
GET /<Set>/$count | The row count as plain text. |
Entity set queries accept $filter, $select, $orderby, $top, $skip, $count,
$search and $expand.
$filtersupportseq,ne,gt,ge,lt,le,and,or,not, parentheses,contains,startswith,endswithandnull.$searchmatches words and"quoted phrases"in the searchable properties, ignoring case. It supportsAND,OR,NOTand parentheses. Words next to each other meanAND.$expandadds related rows through a navigation property, as in$expand=Orders($select=Id,Total;$filter=Total gt 100;$orderby=Total desc;$top=5). Inside the parentheses it accepts$select,$filter,$orderby,$topand a nested$expand.- A collection navigation answers an array. A single navigation answers an object, or
null. $expandhas a depth limit and a limit on navigation properties per level.$searchhas a length limit and a term limit. A query past a limit answers400.- Large results are paged. Each page carries
@odata.nextLinkuntil the last one. Prefer: odata.maxpagesize=<n>sets a smaller page size.- Every answer carries
OData-Version: 4.0. - A query that cannot be read answers
400in the OData error format. $searchon a type with no searchable property answers400.$expand=*, a navigation with no entity set or join, and an expand that cannot run where the rows are kept answer501.$batch, delta links and$applyare not supported.
Keys, policies, limits and analytics work as on every deployed API. See Calling a deployed API.
Download the documents
API Studio > Design > Docs on an OData API has an OData documents card.
- $metadata (CSDL) downloads as XML or JSON.
- Generated OpenAPI 3.1 downloads as JSON or YAML.
Read it from Excel
- Deploy the API and create an API key. See Clients and keys.
- In Excel, open Data > Get Data > From Other Sources > From OData Feed.
- Select Advanced and enter the service root URL.
- Add the header
X-API-Keywith your key. - Pick an entity set and select Load.
Read it from Power BI
- In Power BI Desktop, open Get Data > OData feed.
- Select Advanced and enter the service root URL.
- Add the header
X-API-Keywith your key. - Pick an entity set and select Load.
- Select Refresh to read the rows again.