Getting Text Objects out of a complex List from API Response

Hi!

I’m quite desperate trying to figure out how to get pageVariables out of an API-Response after using a scanned QR-Code to set the GET Parameter.

My Problem is this:
The response contains a complex list, but I only need a little bit of information to show it as text in input fields.

{
“code”: 200,
“count”: 1,
“devices”: [
{
“UDID”: “XXXXXXXXXXXXXXXXXXXXX”,
“locationId”: 0,
“serialNumber”: “XXXXXXXXXXX”,
“assetTag”: “”,
“class”: “ipad”,
“model”: {
“name”: “iPad (5th generation, Wi‑Fi)”,
“identifier”: “iPad6,11”,
“type”: “iPad”
},
“os”: {
“prefix”: “iOS”,
“version”: “14.6.0”
},
“name”: “XXXXXXXXXXXXXXXXXXXX”,
“owner”: {
“id”: 1,
“locationId”: 0,
“username”: “SattlerP”,
“email”: “XXXXXXXXXXXXXXXX”,
“firstName”: “Philipp”,
“lastName”: “Sattler”,
“name”: “Philipp Sattler”,
“vpp”: [
{
“status”: “Registered”
}
],
“notes”: “”,
“modified”: “2021-09-19 19:06:38”
},
“isManaged”: true,
“isSupervised”: true,
“enrollType”: “dep”,
“depProfile”: “GSWT Default”,
“groups”: [
“GSWTLehrer”,
“GSWTLehrer”
],
“batteryLevel”: 0.58,
“totalCapacity”: 32,
“availableCapacity”: 24.6022,
“iCloudBackupEnabled”: false,
“iCloudBackupLatest”: “0”,
“iTunesStoreLoggedIn”: false,
“region”: {
“string”: “”
},
“notes”: “”,
“lastCheckin”: “2021-09-30 16:08:51”,
“modified”: “2021-09-30 16:06:22”,
“networkInformation”: {
“IPAddress”: “185.80.170.82”,
“isNetworkTethered”: “0”,
“BluetoothMAC”: “XXXXXXX”,
“WiFiMAC”: “XXXXXXXXXXX”,
“VoiceRoamingEnabled”: “0”,
“DataRoamingEnabled”: “0”,
“PersonalHotspotEnabled”: “0”
}
}
]
}

I tried mapping the list to a Variable but even with exactly the same properties in the pageVariable Composer tells me it’s not compatible. I tried it with the formula

MAP(data.mydata, {pageVariable: item.data.mydata})

but that doesn’t work either.
The solutions seem to be just in front of me, but I just don’t see it.

Thanks for your help!

Philipp

Hi, you cannot transform the data directly into a page variable, you have to create the page variable first.

If you first create a list type page variable with object properties name and email, and your data is in a more complex format, you can then use “Set page variable” flow function with a formula such as:

MAP(data.myData, {name: item.owner.name, email: item.owner.email})

to set information from your list into the simpler list in the page variable.

Thank you Mari,

I tried this, but I get Warnings:

And even with accepting the warnings, the Variables are not shown in the input fields. Sadly the API only gives out a list even with query parameters on. Is there maybe a way to change the response schema to get data thats easier to handle?

Hi, you can drop fields out of the schema but not modify it directly. What are exactly the fields that you’d want to get out of the response? I think I understood incorrectly that the response is a list, but it seems to be an object that contains a property which is a list :slight_smile:

Yes, that’s it. I already looked up in the documentation, but there is no way of getting not an object wit 3 properties of which one is the list with 25 properties with the information I need. I only can get the collection of all devices, so I use a query parameter to get the List for the device I’m looking for. :see_no_evil:

I need
data.mydata.devices.UDID, data.mydata.devices.model.name, data.mydata.devices.name, data.mydata.devices.owner.name and data.mydata.devices.groups.

Is it even possible to map the data within data.mydata.devices with a “.” ?

If you are just interested in the devices list, you can use “Get collection” configuration instead of “Get record” and mark devices as the “Response key path” in the configurator.

Then, you can set it into a list type data variable, and if you’re certain that there will always just be one item in the list, you can refer to it in formulas as data.devices[0]

Also with your current config you can access the first record in devices list with data.mydata.devices[0].UDID.

1 Like

So with e.g. data.mydata.devices[0].UDID I could theoretically set 5 different pageVariables for each information? With e.g. data.mydata.devices[0].UDID

Yeah if you have a page variable for the UDID text, you can set it with that :slight_smile:

Okay, I will try out this way. Thank you very much Mari! I’ll response here if it worked. xD

1 Like

EUREKA!

Any Tipps for a good Tutorial concerning syntax? :innocent:

Sweet! Check out this video on formulas syntax:

We’re also cooking up a special new formulas tutorial video, so stay tuned for that :slight_smile:

1 Like