Power Community

Power Community

Power Apps portals: Query data using portals Web API (public preview)

Headshot of article author Neeraj Nandwana

Web API operations in portals so far were limited to creating, updating, deleting, associating and disassociating tables. With this public preview, we’re adding the capability to retrieve data using GET requests through portals Web API

The feature provides the following capabilities during this public preview:

  • Query records
  • Apply system query options
  • Request specific properties
  • Filter results
  • Order results
  • Aggregate and grouping results
  • Retrieve a count of rows
  • Column comparison
  • Retrieve related table records with a query

Prerequisites

  • Enable table and field for Web API operations. More information: Site settings for the Web API 
  • The portals Web API accesses table records and follows the table permissions  given to users through the associated  web role. Ensure you configure table permissions  accordingly. More information: Create web roles

Site setting for Web API read operations

You must configure the site setting WebAPI/enableReadOperationPreview and set its value to True to enable read operations using portals Web API.

OPERATIONMETHODURI
Retrieve table recordsGET[Portal URI]/_api/accounts

Example:
https://contoso.powerappsportals.com/_api/accounts

Use $select and $top system query options to return the name property for the first three
accounts
GET[Portal URI]/_api/accounts?$select=name,revenue&$top=3

Example:
https://contoso.powerappsportals.com/_api/accounts?$select=name,revenue&$top=3

Retrieve account by using account IDGET[Portal URI]/_api/accounts(e0e11ba8-92f6-eb11-94ef-000d3a5aa607)?$select=name

Example:
https://contoso.powerappsportals.com/_api/accounts(e0e11ba8-
92f6-eb11-94ef-000d3a5aa607)?$select=name

OPERATIONMETHODURI
Retrieve table recordsGET[Portal URI]/_api/accounts?$select=name,revenue&$filter=revenue gt 90000&$top=3

Example:
https://contoso.powerappsportals.com/_api/accounts?$select=name,revenue&$filter=revenue gt 90000&$top=3

OPERATIONMETHODURI
Use the $select system query option to limit the properties returnedGETPortal URI]/_api/accounts?$select=name,revenue&$top=3

Example:
https://contoso.powerappsportals.com/_api/accounts?$select=name,revenue&$top=3

Use the $filter system query option to set criteria for which rows will be returned.

Standard filter operators

OperatorDescriptionExample
Comparison Operators
eqEqual$filter=revenue eq 10000
neNot Equal$filter=revenue ne 10000
gtGreater than$filter=revenue gt 10000
geGreater than or equal$filter=revenue ge 10000
ltLess than$filter=revenue lt 10000
leLess than or equal$filter=revenue le 10000
Logical Operator
andLogical and$filter=revenue lt 100000 and revenue gt 2000
orLogical or$filter=contains(name,'(sample)’) or contains(name,’test’)
notLogical negation$filter=not contains(name,’sample’)
Grouping Operators
()Precedence grouping
  • $filter=(contains(name,’sample’) or contains(name,’test’))
    and revenue gt 5000

Standard query functions

The Web API supports these standard OData string query functions.

FunctionExample
contains$filter=contains(name,'(sample)’)
endswith$filter=endswith(name,’Inc.’)
startswith$filter=startswith(name,’a’)

Specify the order in which items are returned using the $orderby system query option. Use the asc or desc suffix to specify ascending or descending order respectively. The default is ascending if the suffix isn’t applied.

OPERATIONMETHODURI
Specify order using orderbyGETPortal URI]/_api/accounts?$select=name,revenue&$orderby=name asc,revenue
desc&$filter=revenue gt 90000Example:
https://contoso.powerappsportals.com/_api/accounts?$select=name,revenue&$orderby=name asc,revenue desc&$filter=revenue gt 90000

By using $apply, you can aggregate and group your data dynamically as seen in the following examples.

ScenariosExample
List of unique statuses in the
query
accounts?$apply=groupby((statuscode))
endswith$filter=endswith(name,’Inc.’)
startswith$filter=startswith(name,’a’)
OPERATIONMETHODURI
Use the $count system query optionGET[Portal URI/_api/accounts/$count

Example:
https://contoso.powerappsportals.com/_api/accounts/$count

OPERATIONMETHODURI
Compare columnsGET[Portal URI]/_api/contacts?$select=firstname&$filter=firstname eq lastname

Example:
https://contoso.powerappsportals.com/_api/contacts?$select=firstname&$filter=firstname eq lastname

OPERATIONMETHODURI
Use the $expand system query option in the navigation propertiesGET[Portal URI/_api/accounts?$select=name
&$expand=primarycontactid($select=contactid,fullname)Example:
https://contoso.powerappsportals.com/_api/accounts?$select=name
&$expand=primarycontactid($select=contactid,fullname)

Your feedback will help us continue to build on and improve the capabilities of this feature. We want to hear from you!

See documentation here for detailed overview.

Thank you,
Neeraj Nandwana

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Enhance Competitor Analysis with Integrated Maps within Dynamics 365 CRM

“Keep your Friends Close but your Enemies Closer”- Sun Tzu In a business, it is not just about sincerity but...

More Articles Like This

- Advertisement -spot_img