11

I'm trying to get the JSON text results, e.g.

[
    {
        "TABLE_NAME": "UpdatePlanning"
    },
    {
        "TABLE_NAME": "StoreInfo"
    },
    {
        "TABLE_NAME": "InSiteTxPerHourPerDay"
    },
    {
        "TABLE_NAME": "inSiteTaskRecordsLocal"
    },
    {
        "TABLE_NAME": "InSiteStoreInformation"
    },
    {
        "TABLE_NAME": "InSiteLogExtractionTest"
    },
    {
        "TABLE_NAME": "InSiteDailySalesPerDay"
    },
    {
        "TABLE_NAME": "FredOfficeLogAlerts"
    },
    {
        "TABLE_NAME": "DPTestAutoScaleTable"
    },
    {
        "TABLE_NAME": "DPGenHoldTable"
    },
    {
        "TABLE_NAME": "DPDailyTopSellerItems"
    },
    {
        "TABLE_NAME": "DPDailyTierSales"
    },
    {
        "TABLE_NAME": "DPDailySales"
    },
    {
        "TABLE_NAME": "DPDailyAvgBasketSize"
    },
    {
        "TABLE_NAME": "ASGInSiteStoreInformation"
    }
]

From a web API I have wrapped in a 'custom connector' to use in PowerApps. My custom connector works great, and I can test it within the custom connector screen OK, but I can't figure out how to access that JSON data within Power Apps to - for example - populate a data table, or populate a list, or gallery, or even just a label? Bear in mind the JSON schema returned from some of the GET methods aren't fixed, e.g. the JSON structure can be different depending on the type of object queried etc, but no matter what I can't get it working.

Example: I've tried this in my OnStart method for the first screen in the PowerApps app

Set(myTable,InSiteConnector.gettables())

With the assumption my JSON would be stored in the variable myTable.. but if I reference myTable in a lable, or anywhere, it doesn't produce anything. Using the same method for a data table or chart or list is the same, no results. What am I missing here? I've scoured the web, but nothing I try syntax wise seems to work.

Similarly, if I create a data table and try to select my custom connector as the data source, e.g. it is in the list of data sources

enter image description here

But adding it just causes it to show up again and again in this list...

enter image description here

but I can't click it, or do anything with it that seems obvious in so far as getting data from it? (e.g. being able to choose fields from my JSON, or even manipulating the raw BODY back from the GET method(s))

I have started a bounty for someone to please show me a working and replicable example of getting the JSON from this web API into a PowerApps app for use in a gallery or similar. Thank you!

JamesMatson
  • 1,497
  • 1
  • 10
  • 44

1 Answers1

4

The JSON schema for the return data must be defined, any data that does not fit the schema will not be passed back to PowerApps. This is because the schema is used to define the return type in PowerApps for further use. You could say that the connections are strongly typed, in a way.

Below is a screenshot of where you can define the response body in order for the data to 'show up as the outputs in designer', as is helpfully hinted.

What you can do if your schema is variable, is to use Flow to get the data and process it and conform to your defined response schema before returning it to PowerApps.

For example see this blog post. If your response body is variable then you could insert some logic in the Flow after the GetDailySales step to shape the reponse body to fit the JSON schema defined in the Response step.

enter image description here

Meneghino
  • 841
  • 5
  • 13
  • Thank you Meneghino - that sounds reasonable, could I please ask for a simple example of using Flow to get the data and conform it to a standard schema? That comment has me a little stumped. I understand the objective, not the method to get there... – JamesMatson Sep 27 '18 at 13:14
  • 1
    I have edited my answer for clarity. In Flow you can get any shape of JSON response from your data source, and then using some logic and the Compose action, you can re-shape the response to fit the JSON schema you have defined in PowerApps. Difficult to be specific without knowing the kind of variability of your JSON responses. – Meneghino Sep 27 '18 at 13:22
  • No no, that makes perfect sense to me Meneghino, thank you - I can review the Compose action and figure it out from there. I took your suggestion and added the 'strongly typed' response to my custom connector! Great! Now I'm back in PowerApps... and I have a button where I'm calling the 'gettables' function of my custom connector - Set(getTables,InSiteConnector.gettables()) but still not quite sure how to access the 'TABLE_NAME' 'token' i defined in the custom connector (see my original post for what the JSON looks like) – JamesMatson Sep 27 '18 at 13:26
  • In PowerApps set the Text property of Label to getTables. with the dot and see what options are proposed. You access the content of getTables via the . – Meneghino Sep 27 '18 at 13:34
  • I have tried that... but using 'getTables.' in a label just gives me a red 'squiggly' on the dot, saying 'unexpected characters. The formula contains 'Ident' where EOF is expected' – JamesMatson Sep 27 '18 at 13:38
  • This is after I have a) updated my custom connector method to include a response payload bound to example JSON from my response and b) set the value of getTables to the execution of the custom connector method on start of the first screen. – JamesMatson Sep 27 '18 at 13:39
  • Maybe you should use a name for the variable which is not the same as your connector (even though names are case sensitive, you never know). If that does not work, then I am not sure what else to suggest. – Meneghino Sep 27 '18 at 13:44
  • I'll keep playing around, thank you... I've tried loading the data from the custom connector into data tables, labels, collections, gallery.. you name it. Nothing works. I'm clearly missing something :( Do you have any good links for end-to-end guides on getting a JSON API into PowerApps controls? – JamesMatson Sep 27 '18 at 13:47
  • There are a few post on [this blog](https://baizini-it.com/blog/) that may help. I can address any specific questions on those. – Meneghino Sep 27 '18 at 13:51