This article walks you through how to create an Xledger connector in a Power Automate Flow, using the Xledger GraphQL API. The Flow we're going to show you in this article is a very basic one, but a good starting point to show you the possibilities of using Xledger in Power Automate. The Flow we are creating in this example is extracting the last 10 employees from your Xledger entity, to a Google sheets file.
Note: Xledger supports its own API but does not support integrations built using Power Automate, this is owned and maitained by the customer/partner building them (refer to Integration approaches for more details).
Before you start you will need the following:
- Xledger GraphQL API token.
- A Power Automate account.
- Access to your Xledger GraphiQL environment.
- Postman account.
- Google drive account.
How to build your Xledger Power Automate Flow:
- Firstly, please click on 'My Flows' in the left hand side of the page.
- You will now be on the 'Flows' screen, please click on the 'New flow' option in the top left hand corner.
- This should then give you an option to select the type of flow you wish to build, for this example please select 'Instant cloud flow'.
- You will now be presented with screen below, asking you how you wish to trigger this flow:
- Please enter a relevant name in the 'Flow name' field.
- Next, you need to select how you wish to trigger this flow. Please select 'Manually trigger a flow', followed by selecting 'Create'.
- You should now be taken through to the developing screen and see the 'Manually trigger a flow' step. From here, please select '+New step'.
- Power Automate will now prompt you to 'Choose an operation', in the search field please enter 'HTTP' and select on the HTTP action.
- You now need to enter the correct details in the HTTP action for it to work. The first setting you need to enter is the 'Method', please click on the drop down and select 'POST'.
- Next, you need to enter the GraphQL URL into the 'URI' field, like the image below: (please make sure to keep all of the URL in lower case)
- The next step is creating two headers, the first header you need to create is called 'Content-Type'. In the 'Enter key' field please enter 'Content-Type' and in the 'Enter value' field please enter 'application/json', like the image below:
- The second header you need to create is called 'Authorization'. In the 'Enter key' field please type 'Authorization' and in the 'Enter value' field please enter the following: token <enter your GraphQL API token here >.
- Next, you will need to go to the Xledger GraphiQL environment, and select query you wish to use. In this instance we're going to use 'Employees'.
- Now, you have your Xledger Employees query we need to convert this into a HTTP string. To do this we're going to have to use an online application called Postman. If you do not have a Postman account, don't worry it's free to set one up.
- Once you've logged into Postman, please click on 'Workspaces' in the top left hand corner and select 'Create workspace'.
- You will then be prompted to enter a name for the workspace, please fill this in followed by selecting 'Create Workspace and Team' and then clicking 'Go to workspace'.
- You should now be in your newly created workspace, in the top left hand corner please click on 'New'.
- This should prompt you to select a 'Building block' for this instance please select 'HTTP Request'.
- You should now be be given the option to fill out the HTTP fields for your request. In the top left hand side of the screen please change 'GET' to 'POST', followed by entering https://www.xledger.net/graphql in the 'Enter request URL' field.
- Next, please click on the 'Authorization' tab, followed by clicking on the 'Type' drop down menu and selecting 'API Key'.
- In the 'Key' filed please enter 'Authorization' and in the 'Value' field please enter 'token <your GraphQL API key>'.
- Now you need to go to the 'Headers' tab, and recreate step 10.
- Once you've added your header, please go to the 'Body' tab. Please select the 'GraphQL' option, and paste in your Employees query from Xledger GraphiQL into the box.
- To confirm you have used the correct details please press 'Send', if configured correctly this will return your Xledger employee data at the bottom of the screen.
- Now you need to extract the HTTP body of the request to put into Power Automate, to do this please click on the '</>' icon on the right hand side of the screen.
- This should open up a box called 'Code snippet', in the drop down menu please change 'cURL' to 'HTTP'.
- Then you need to copy the query code all the way to end, like so:
.
- You now need to go back to Power automate and paste this into the body field, you then need to remove the following variables snippet from the body ',"variables":{}', like so:
- Please press 'Save'.
- Next, you need to add a '+New step'.
- You will now be prompted to 'Choose an operation', in the search field please enter 'JSON' and select the 'Parse JSON' action.
- Please click into the 'Content' field of the 'Parse JSON' action, this should then give you a list of options to choose from. Please select the 'HTTP Body' option.
- Next, we need to generate the schema so Power automate knows what data type each field is in the GraphQL query. To do this, please go back to the Xledger GraphiQL environment and run the Employees query again. Once you have ran the query, please select all of the results in the right hand screen, followed by copying them.
- Once you've copied all the results, please go back to your Power Automate flow and on the 'Parse JSON' action click on the 'Generate from sample' button. This should then bring up a pop box which is titled 'Insert a sample JSON Payload', please paste your query results into this pop up, followed by pressing 'Done'.
- Please press 'Save'.
- You now need to go to Google sheets and login into your account, once logged in please create a google sheets file and name it accordingly. This file will be used in the next few steps.
-
In the file you have just created, you will need to enter field names in the first row which match the Xledger GraphQL results. Using the Employee query results from GraphQL, please select which fields you wish to use. In this case I'm going to use dbId, description, email, code, createdAt and modifiedAt.
- Next, please go back to Power Automate and select '+New step'.
- You will now be prompted to 'Choose an operation', in the search field please enter 'Apply to each' and select the action.
- Now, you need to click into the 'Select an output from previous steps' field, which should return a list options. In the 'Search dynamic content' field please type 'edges' and click on the option.
- You will now be given the option to 'Add an action' within the 'Apply to each' action, please click on this and search for 'Google sheets'.
- This search will return a list of Google sheets options, please click on 'Insert row'. This will then prompt you to login into your Google account.
- Once logged in, you will be given two fields. In the 'File' field click on the folder icon, followed by clicking on the arrow next to 'GoogleDrive'. Finally, then select the Google sheet file you created earlier.
- Next, you will need to select the sheet in your Google sheets file. Please click on the drop down arrow in the 'Worksheet' field, and select the correct sheet. This will then return your field names you created earlier.
- You will now need to match the Google sheets field names to the GraphQL fields from the Employees query.
- Once the field names are configured please press 'Save'.
- Your Flow is now setup and ready to be tested, please press 'Test' in the top right hand corner, followed by selecting 'Manually' and then 'Test'.
- If the test is successful, please go to your Google sheets file and you should see 10 rows of Employees from your Xledger entity.
System requirements
A user with the "Administrator" or “Domain Administrator” role within your Xledger entity, will have to generate a token for you to be able to connect your data. For more info on this please see the Xledger GraphQL documentation, attached to this article.
Troubleshooting
If you’re having issues connecting your data, please check with your Xledger “Domain administrator” that the generated API token is correct and that the token has been granted access to the relevant scope. Please also check that step 28 has been imported correctly, and the ',"variables":{}' string has been removed.
Limitations
There is only one limitation to Power Automate, which is Microsoft does not currently allow us to setup a custom connector to distribute to our customers. This is because in the custom connector setup, GraphQL is not currently supported. This means that instead of using a pre made connector in each flow, you have to create the HTTP action, in every Flow you wish to create.