Dear PA Community,
I am struggling to parse JSON that includes page numbers, etc. The below JSON is for the entities listed in a human capital management system. I've tried initializing a variable as array and object then "apply to" to no avail.
Here is the JSON I receive:
{
"nextPageUrl": null,
"previousPageUrl": null,
"results": [
{
"id": 2784,
"clientCode": "7898",
"clientName": "Tobin Performing Arts",
"links": [
{
"href": "https://www.zzzzzz.com/rest/api/clients/2784",
"rel": "self"
},
{
"href": null,
"rel": "Detailed"
},
{
"href": "https://www.zzzzzzz.com/rest/api/clients/2784/legals",
"rel": "LegalCompanies"
}
]
},
{
"id": 11569,
"clientCode": "Code1",
"clientName": "Biz Group",
"links": [
{
"href": "https://www.zzzzzzzz.com/rest/api/clients/11569",
"rel": "self"
},
{
"href": null,
"rel": "Detailed"
},
{
"href": "https://www.zzzzzzzz.com/rest/api/clients/11569/legals",
"rel": "LegalCompanies"
}
]
}
],
"totalItems": 2,
"totalPages": 1
}
Here is the flow thus far:
Final Answer - THANK YOU Microsoft @v-litu-msft and @DmitriiKubyshev
Sharing so we can all learn:
Scenario: Pull data from 3rd party mgmt system via API using tokens with a multi-page response:
Get the token & request the company names under the account--
Setup an Array for all of the employees coming in. Why? Data arriving is as an object and you can't (or at least I do not know) how to "Do While" or "Apply to Each" reading an object--
Read the JSON for how many pages, put in a variable (string) and convert to an integer. DO UNTIL for every page found on # of page numbers received from initial HTTP request. Using counter, APPEND for pagination, copy the data into compose for processing and convert the results of compose into the array. Once in an array, APPLY TO EACH loop to read and, for us, we are writing the data to a SharePoint list.
wiredupjax,
For this particular case you would need to iterate through the pages manually using "Do Until" loop and 'nextPageUrl' property. You can initialize 'nextPageUrl' variable with your initial url and update it from the response to get the next page. Here is an example flow:
And here is the json schema that I used for parsing of 'nextPageUrl' and 'results' array with 'id' property:
{
"type": "object",
"properties": {
"nextPageUrl": {
"type": "string"
},
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
}
}
}
}
Best regards,
Dmitry
Thank you Dmitry. I was able to successfully get the individual information with the following updates:
HOWEVER, I'm only getting 50 employees because it's producing pages. How do I ask for the "next" page in a flow?
Hi wiredupjax,
'apply to each' extracts individua elements from the array and it looks like the schema for individual employee has an 'array' root type the same way as a list of employee. For individual employee schema try to use
{
"type": "object",
"properties": {...}
}
Meanwhile, you can parse entire response once with "All employee" like that and use its properties further in the designer:
{
"type": "object",
"properties": {
"results": {
"type": "array",
"items":{
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
}
}
}
}
Best regards,
Dmitry
Thank you!
I was able to successfully compose, initialize and parse the JSON.
However, when I move into "apply to each" it's still complaining it's an object.
Hi @wiredupjax,
You could use the expression to extract the array of results and append it into the array variable, for example:
outputs('Compose')?['results']
Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.