cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TaSpanja
Frequent Visitor

Unable to parse graph api json result

I created a test where i have an array of users and then i parse the array and use it to populate a list in sharepoint. This works perfectly, next i wanted to use graph api to pull the array of users from azure ad and the result is as follows:

 

{
  "responses": [
    {
      "id""1",
      "status"200,
      "headers": {
        "Cache-Control""no-cache",
        "OData-Version""4.0",
        "Content-Type""application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
      },
      "body": {
        "value": [
          {
            "id""021b0b14-4323-4f0a-8a09-48073873180e",
            "displayName""Raul Razo",
            "mail"null
          },
          {
            "id""b25cc84e-4f88-4a10-8b48-0266c7a6e45a",
            "displayName""Conf Room Stevens",
            "mail""Stevens@M365x500340.OnMicrosoft.com"
          }
        ]
      }
    }
  ]
}
 
and that is ok as well, the problem comes when i try to parse the results which return the following:
 
[
  {
    "message""Invalid type. Expected Array but got Object.",
    "lineNumber"0,
    "linePosition"0,
    "path""",
    "schemaId""#",
    "errorType""type",
    "childErrors": []
  }
]
 
the schema for the parsing is:
 
{
  "type""array",
  "items": {
    "type""object",
    "properties": {
      "id": {
        "type""string"
      },
      "displayName": {
        "type""string"
      },
      "mail": {
        "type""string"
      }
    },
    "required": [
      "id",
      "displayName",
      "mail"
    ]
  }
}
 
I have tried multiple different schemas and non have worked.
 
I believe that the problem is with this part of the response in the graph api result:
 
{
  "responses": [
    {
      "id""1",
      "status"200,
      "headers": {
        "Cache-Control""no-cache",
        "OData-Version""4.0",
        "Content-Type""application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
      },
      "body": {
        "value":
 
 
is there a way to trim this out of the body and parse the remainder?
1 ACCEPTED SOLUTION

Accepted Solutions

For those of you who might be interested I have found the solution to this issue, basically it is to first parse the JSON result from the graph api, then you need to compose or call the array section into a loop and parse that section one more time and that is it data from graph api request is now usable. Screenshots below to support this method:

 

Screenshot 2020-06-30 at 03.00.57.png

 

View solution in original post

6 REPLIES 6

@TaSpanja 

Hey there.  This might be kind of "hacky", but you could use a split() to separate the whole thing on the phrase, "value".  It might look something like this:

 

split(<GraphAPIBody>, '"value":')[1]

 

Not totally sure if that will work, but you'll replace the <graphAPIBody> bit with the dynamic output of that step.  Note that "value" will also have single quotes around it and that I also included the colon.  This splits the whole thing in two, and the [1] at the end says that you're only interested in the second half.

 

Keep us posted.

-Ed

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

I am fairly new to this so can you please guide as to where in my flow this would go, i tried this but it did not work:

 

split({
  "requests": [
    {
      "url": "/users",
      "method": "GET",
      "id": 1,
      "headers": {
        "Content-Type": "application/json"
      }
    }
  ]
}, '"value":')[1]

 

My Flow is as follows

 

Screenshot 2020-06-05 at 17.59.56.png 

@TaSpanja 

Hi there, sorry for the delay.  So the thing to try first is to put a compose action after your HTTP, but before your parse JSON.

 

Inside the compose, use that split that I listed above in the expression box:   split(<Batch Body>, '"value":')[1]

 

<Batch Body> would be the dynamic value output of your HTTP action, just like you have it in your ParseJson step.  So you would open the expression editor, type out 'split('   (without the quotes), click over to dynamic values and click on the body, the type the rest of the expression from the comma on.

 

Hopefully that makes sense.  Let me know if you get stuck.

-Ed

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

Sounds Great, I will give it a try first thing monday morning.

 

Thanks will let you know how it goes.

Hi Ed,

 

I have tried the below as instructed but to no avail results are below:

 

Configuration Option 1, Option 2 and Option 3:

 

Option 1 - trying to parse without splitting

Option 2 - trying to split document using expression (requires an input of type string not object so i need to somehow convert the object to string

Option 3 - Wrote code directly to compose (does not work at all just concatenates the information added)

 

Screenshot 2020-06-08 at 14.21.04.png

 

Screenshot 2020-06-08 at 14.21.24.png

 

 

In the mean time I managed to created a working solution for what i required which is as follows below, but i would still like to troubleshoot the above issue:

 

Screenshot 2020-06-08 at 14.27.55.pngScreenshot 2020-06-08 at 14.28.39.pngScreenshot 2020-06-08 at 14.28.47.png

For those of you who might be interested I have found the solution to this issue, basically it is to first parse the JSON result from the graph api, then you need to compose or call the array section into a loop and parse that section one more time and that is it data from graph api request is now usable. Screenshots below to support this method:

 

Screenshot 2020-06-30 at 03.00.57.png

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (4,243)