Send Array/JSON Response from Power Automate Flow to Power Apps #PowerApps #PowerAutomate #Response

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
have you ever had a requirement to send a json response or an array from power automatic flow to the power apps if the answer is yes then stay tuned in this video i will show you how you can send a json response or an array from power automate to power apps without using any premium connector [Music] [Music] hey everyone welcome back to my channel i am deepak srivastav thanks for subscribing and thanks for watching my videos in today's video we're gonna see how you can use a very simple approach to send a json response that you may be receiving from an api or from a custom connector or any array response directly to the power app and to understand the scenario uh let me walk you through with an use case uh this is the use case that i'm using to walk you through you can apply the same method for any of the use case that you may have okay so what the use case that we're going to use today i'm going to try to create an app or i want to create an app that should connect to my sharepoint and give me all the groups sharepoint groups not the m365 security group the sharepoint group and i i should be able to see all the users inside those groups right so i'm going to just show you the query part of it if you want to extend this app and also add some operations where you can add a user to a particular group or create a new group that also very easily possible and if you like to see that extension leave the comment i will create another video to create those operation as well but this video is all about creating the response that is an array okay so the first thing that we need to know how we can query all the group from the sharepoint okay so for that i'm going to use the sharepoint api and the api is pretty simple and i'm going to show you that api and the api is this is my sharepoint url so you can copy the url that you have underscore api where site groups what this api does it's going to query your sharepoint and give you all the sharepoint groups that you have and the second api that we need is to query all the users from the given group okay so that api is also very straightforward okay so this is the api again this is my url of the sharepoint underscore api web site groups and now what we are doing we are saying get by id so we are saying okay give me the group and we need to pass the id and then all the users for that very simple straightforward api the challenge with those api that yes those are very simple but we don't have a very simple and easy way to call this ap call these api from the power apps itself so what i'm going to do i'm going to start creating the app and then we're going to call a flow from the tab call this api get the response that we are getting convert that response in a way that we can easily pass that response from flow to the app so let's log into the make.powerapps.com and we're going to create a simple app okay so i created my app so the app is empty right now and what i'm gonna do i'm gonna actually insert a gallery okay this is my first gallery that will show me all the groups align it here and we just need the title because that's the only thing i'm gonna show the name of the group add one level here okay so i added these two labels here uh sharepoint groups and the user and i'm going to drop another gallery also for the users okay and let's drag it here so it will align and in this case i'm gonna say title and subtitle because what i'm gonna show the name of the user and the email address and for our this gallery the user gallery i don't need the separator and i also don't need the next arrow okay so our basic structure is ready now we need to connect and query okay so the first thing that i'm going to do of course you don't forget to save it now from here on the on the left navigation you see this is the small icon for power automate click there and we are going to create a new flow okay this is the flow that going to help us running those api that we had and sending the response back to this power app click on create new flow okay i'm gonna create from blank okay and this is the cool right it's gonna open the power automate inside the powerapp experience so pretty cool first thing that i would generally do i'll rename so that i can give a good name okay so the name of my flow i'm keeping cat user groups now as you notice from our app we are calling this flow and i don't want to create multiple flows so what i'm going to do i'm going to create one flow and then from powerapps i want to pass whether i need all the groups or i need all the users for a given group so what i want that when i'm calling this flow from my app i need to pass the request type whether i want groups or i want users so for generally what you should do add a compose and before making any change rename it and call it request type or whatever name you wanted to give and then what i'm going to do i'm going to select this input and ask in powerapp this ask in powerapps is nothing but you are adding this parameter to your flow so when powerapp is going to call these flow the user or the app has to pass those parameter values okay click on ask in powerapp and the reason now you understand why i ask you to change because if you don't change the name of the action the parameter name will be created with the name so if i have compose it's going to be composed underscore input and when you are using this flow in power app you don't know what i need to pass so it's better a good practice to change the action name before you do asking powerapp so that's the one thing the second information that i want if i am i want to get all the users for a given group i need to pass the group id if you remember the api you need to pass the id to get all the users right so i'm going to do the same approach again compose rename it okay and then ask in power perfect so we created two variables or two parameter that we need to pass when we are gonna call this flow now let's use this parameter so the first thing that we're going to check the request type whether the request is for all the groups or request is for all the users so i'm going to add a condition and then output of this request type and if this is equal to groups so if my request type is equal to groups then i'm going to do what i'm going to use sharepoint api action to send an http request to sharepoint okay site address this is my sharepoint site method is going to be the get and the uri is the same what i have shown you the uri is underscore api web site groups okay this will give me all the groups similarly if i go to the right hand side i'm going to do the same thing sharepoint send an http request again my site address method is going to be the get and the api as you know this one the only thing we want to change here you see i have hard coded three you don't want to do that instead i'm going to use this group id the one that i'm getting from the power app okay click save now if you go to floor.microsoft.com or makerpowerautomate.com you will come here here if you go to my flow you should be able to see the flow that you just created so this is here get user group and now you can edit the flow from here so you don't need to go to the power app and click edit you can do that as well so so far we are just making the request we have not made any change so what i'm going to do here i'm going to test this real quickly because i like to show you the response that we get from this api because this is the first thing that you need to understand when you are passing or sending the array or json response from power automatic to powerapp you have to understand or know the response that you are getting because that will help you to convert that response to another array that you can send to the powerapp okay so do that let me run it it's going to ask me those parameter okay so here i'm going to just say groups first we will check the group and then later we will check the users also so you can see the flow got completed successfully and it should go here so as you can see and now if you look at the response starting with the results so that's the typical structure of the sharepoint api response and then if you look after this i am getting the response here for each group so this is id 5 the group group name is a communication site members that's the first group and then if i keep going down i will see other group like this in the second group site owners if i keep going site visitors so now you can see how i'm getting the response and just to give you a better understanding of the response i copied the response into my vs code okay so this is the response as you can see here d results and then after that you have these different array element for each of the group right i want to make uh another array and why i'm making that another array because if you look at the response that you are getting from these sharepoint api it's very complex and this can happen with any of your api that you are using or custom connector that you are using the response may be more complex so what you need to do the first thing you need to make this response simpler and only include the column that you actually practically gonna need in your app because most of the time we don't really need going to use all the columns or information that we are getting from the api we generally use only few okay so for that what i'm going to do i'm going to use another action called select okay so under data operation you can find the select and what select can do it can create an array based on another array okay so in here in the prom this is my response that i'm getting from this send an http request to sharepoint but if i use the body body is this entire thing right so this is not an early the entire body is not ready so what you need to do you need to go till the end results that's after that your repeated element will start the same thing you can apply to your api response that you're planning to work you need to go to the point where you can have those repetitive information coming from your api okay so in our case what i'm going to do i'm going to copy this this body that we had clicked go to the expression paste it okay remove the curly bracket from the front and the end okay so you can see the body and then action name if you rename the action you need to change this as well then i'm gonna do question mark bracket single quote d if you remember question mark bracket single quote results okay so what we are saying this is my array response that i'm getting okay that's done now the second part that is map so what map is saying on the first column here you can give the name that you want in your new array and the value we need to pick from the response that you are getting okay so in here what i want to pass the person that i want to pass the id so this this is going to be the group id and how you will get the id if you look at the response i'm getting id in this field id right so i need to read this information now because we are using this already the lead results this is my item and i need the id okay very simple go here in the value go to the expression i'm gonna say items or whichever item i am on id okay so this is how you will map the response that you are getting in your api to the new array that you are creating i also need the title it's going to be the very same i'll go to the value expression and then instead of id this is my title because this is the title is the name of the column okay okay now if i want more information to pass on to the to my app i can absolutely do that for example if i want if i want to pass let's say any of this information owner title who is the owner of the group description if there's any and any other information that you can see right you can pause for example description so let's say i also want to pass the description go to the value expression paste it okay now you need to remember one thing if i'm gonna use the description and pass like this right this is the first thing that you need to remember if you are using this method the array that you are creating the new array that eb will pass to the power app none of these column should have a null value because if any of these column will have a null then your app will not understand the response so what you need to do in that case if you don't know that which column or which field is going to have the knob you need to apply the method that i'm going to show just now to every field that you're going to create here or if you know that some of the column or field will always have the information then you can use like i'm using for id and title because we know the id and title cannot be empty for the sharepoint group description maybe so what you need to do in the description i need to check for if this is empty empty means no okay so i'm gonna say if empty this is another function okay so if this is empty okay that means it's true then what i'm gonna do i'm gonna just pass this double single quote okay so that may it will pass as an empty string rather as null and if it is not empty then you can easily pass whatever value it has okay also close it okay so very simple if statement if you want to use a particular field and you you are not sure that if that field will be empty or not use this if statement that will make sure that it will work all the time perfect let me save it okay so this part is done the next what we need to do we need to now send it back to the power app so i'm gonna search for power app okay and in the powerapp there is a action called respond to a powerapp or flow it's like that click on add output and as you can see here right now these are the only type that you can send it back to the power automate and as you can see here the array or json is not listed here today in the future i hope that the power automate will have that capability and functionality to send array directly from here to there but because it's not there right now we're going to utilize the text type so select the text give a name of your respond and in the value you actually need to pass whatever output that you are getting from the select and how you will do that go to the expression and i'm gonna use the body okay so body as you can see here you need to pass the body and then action name our action name here is select okay i can rename also this one so it's easy to understand okay i renamed it for sp group and i go to the respond expression body and here i'm gonna just type the name of my action that is sp group so single quote spgr okay save it so now we have done this half part now we'll go let's go back to the power app and again if you go to the power power automate here in these three dots i can refresh okay so it will get the latest change that we have done now what we need to do whenever this app load i want to make that query to get all the group and how i would do that if i go to the app select the app on start so whenever the app is going to start i'm going to make that query okay and what i'm going to do on on start we need to call that flow that we just created and not only that we need to call that flow and the response you remember we are sending that response uh from our custom array that we created we need to assign that response to a particular collection so that we can use it so i'm going to start with set this is how you create the variable okay so this is the name of my variable and now what i what you need to do is start typing the first initial of the flow that you have created and it will automatically show you so the name of the flow that we have is get user groups okay so i'm going to say get and you see here get user groups dot run once you select that look at the top it is saying that you need to pass the request type and also the group id because these are the two very two parameter that we have created so our request type is because we need all the groups and i'm gonna pass nothing into the group id because this request is for group when we made the user call we will pass the id here close it dot response okay and we're going to close the bracket so what we have done we are calling that flow that we have wrote and whatever response that we're going to get we're going to assign to this variable okay and just to test what we are getting here i will go to the app click on these three dot turn on start this should trigger my flow and if you go back to flow it does as you can see here five seconds ago and if i go back to my app and look at the response and as you can see here so i'm getting the response now this is where the trick is done let me first show you the response or how the response is coming in and what we need to do to make it work okay so this is how the response is coming in it's coming as in string but it is it has all the information that you want so id the title so somehow we need to convert this string to an array in the powerapps now this is where the where the challenge is right because we don't have a direct rhs on request response between powerapp and flow we can only pass information as a string okay so to convert this string to an array i'm going to use another function there is a a function called match all okay and measure function is nothing but what it does it matches the string that you are receiving and give you uh a matched response in our requirement so to start with i'm gonna use the clear collect because i want to collect that response that i'm getting after my match all to an object again okay and then the function is match all as you can see here that's all now it is saying okay match all then in which text okay so text is nothing but that you see the response that we are getting because we are getting response in a text format then there is a something called regular regular expression the regular expression is nothing but it is asking me how the response that you are getting in text is looking like or from where i need to get the information okay so i copied the response this variable response text that we are getting into this file so i can easily walk you through and read it through and as you notice this is how we are sending the response and if you notice here it looks like an error already but because we are sending it as a string or as a text the power app is not able to understand so our pattern or regular expression so it's going to be like this now let me walk you through and how easy it is to maintain and change it looks like little trickier but it's not that trickier so you will always start with double quotes and then you will have these brackets here okay and then if you notice these the first part here on each of there so you so you have the id that's your first column title that is your second column description that is your third column you can keep adding as many column as you want or you are sending from your power automatic flow but if they have to be in the sequence how they are structured so i cannot put title before id because id is my first column it has to start with id so my column name and then double double quotes so double quotes double course id the name of the column and then close both the double quotes colon this is not going to change then you will have a bracket question mark again the name of the column this is how the information is coming right but you are having this greater than or smaller than icon here then you have the parenthesis carrot sign double quotes carrots and close star and then you close your bracket okay so this is to here is your structure for any column now there is a couple of things you can notice if your response that you're getting is a type integer then you don't need to have this inside the double quotes like you have for title okay so if it is a text column then you need to then you need to close it in inside these double double quotes if it is a number column then you just need to have this structure everything is going to remain the same the only thing will change the name of the column that you are using okay so this is done so now i should be getting all my formatted result in this obj result table okay let's try to run it again so i'm gonna go to the three dot and click on start to see whether this part is working or not and as you can see all right so now if you notice i'm getting the id this is what i ask for i'm also getting the title and also the description should be there now now you as you can see here we converted that text string that we're getting to the well formatted table i can use that table as the source for my gallery so instead of custom i'm gonna say obj results okay and in this one i'm gonna use the title and as you can see if i go to this item dot description id title all the all the columns that i have already showing up here i'm going to say title and here you go all of my sharepoint groups are listed here pretty straightforward right the group ready now we need to fill this one so what we need to do we need one click of this this icon we need to call the same flow again but this time what we need to do we need to pass the request little differently so we can get the users back okay so on select the method is same i'm going to create another variable so this time users and then get user group.run this time request type is users and this is where the trick is right so i'm gonna pass this item.id so this is where i'm passing the group id where i'm making this click okay so this is gonna give me the response back before i move forward let's go back to the flow and complete the second part right let's go to the flow and we need to complete this part as well okay so i'll go to the condition and here very same thing i'm going to add another select because i want to convert the response to my format and this time i'm going to rename this to users because this is the users from you know the response the response from this is also going to be the very similar what we get here it's just the data it's gonna change so i i'm gonna do the same thing again go here select the body right copy it go to the expression paste it back remove the curly from front and end and then go all the way to the end question mark d question mark results okay and again this part may change from your api or your response you need to make sure that you are picking the right right response okay and then what i'm going to pass here or the mac id as you know already so i'm going to say item id this is my user id actually okay and the title so this is the name or the display name if you say and then email okay so i am sending the id of the user user display name that comes in the title and the email for that user okay and same thing we need to respond back to the power app so response and response is going to be the output of this select or the users so go to the expression body and then i'm going to just type the name of my action click ok save so your flow is ready now based on the request it's gonna either send you all the groups or it's gonna send you all the users let's come back here i will go to the flow refresh it so it will get all the latest and greatest okay and on click of this button and that's what we are doing i'm going to copy this entire thing because this is what we're going to reuse i'll go here and then paste okay and i'm going to change the name of my collection so obviously user results this is what the variable users right and then you can quickly look here your arrays you are saying id title and email right so ids id title is titled instead of description i'm going to just change the name here and this is how easy it is to change okay so if you notice how quickly i mapped my new column with new response right because this was the new response that i'm getting there's no user information and that's what the cool thing about it once you have it once done you can reuse for any other response okay so if you notice i'm getting into the reason if you have noticed so far i have not actually passed the response yet so dot response i have to do that to get the response okay okay now i'm gonna run the app click here it should make the call to my power automatic flow and then change it okay so go here open it and if you look at the user results there you go i'm getting all the users so the now the only thing that i need to do this gallery we need to map the right response so always a user result and then this is the type this is the title this item.title and then this item dot because this is what i wanted to show awesome now if i run the app i can go to any of these different group and i can see the different users that has been added pretty cool right okay so so far we created this functional app where you can query all the groups and all the users yeah so that's it for today uh i hope this will help you in your app where you have a requirement to to get array or json object from power automatic flow to your power app and also don't forget to leave me a comment if you like to see this app more functional where i can create a user create a group remove a user remove or delete a group from the powerapp i would definitely love to create that extend this app and show you guys how to do it thank you very much for watching this video don't forget to subscribe thank you very much
Info
Channel: Deepak Shrivastava
Views: 16,807
Rating: undefined out of 5
Keywords: microsoft flow, power automate, power apps, send api response from flow to powerapps, retrieve api response in power apps, send multiple rows from flow to power apps, flow and power apps with multiple json response, send json response from power automate to power apps, send response back to powerapps with json array, send json array from microsoft flow to powerapps, powerapps, power platform, deepak, flow, flow return data to powerapps, microsoft flow http json, sharepoint groups
Id: N1pPUvFeWUk
Channel Id: undefined
Length: 30min 44sec (1844 seconds)
Published: Wed Jul 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.