How to consume GraphQL APIs from Azure Logic Apps
Tags: azure, logicapps, graphql, lowcode
Published: 2022-11-28 06:39:49

---
title: How to consume GraphQL APIs from Azure Logic Apps
published: true
date: 2022-04-05 00:00:47 UTC
tags: Azure,LogicApps,GraphQL,LowCode
canonical_url: https://blog.siliconvalve.com/2022/04/05/how-to-consume-graphql-apis-from-azure-logic-apps/
---

If you’ve been reading my blog for a while then you will see that I am a heavy user of RESTful APIs in my solutions, going so far as to build a custom [Azure Logic Apps Connector for Meetup’s REST API](https://github.com/sjwaight/LogicAppsMeetupReadOnlyPublicConnector). I’ve used this Connector in a few places and blog about one example previously in [Integrate Meetup announcements with Microsoft Teams using Azure Logic Apps and Adaptive Cards](https://blog.siliconvalve.com/2019/05/24/integrate-meetup-announcements-with-microsoft-teams-using-azure-logic-apps-and-adaptive-cards/).

Recently my solution for Meetup integration ceased working as Meetup decided to shift their API from REST to GraphQL without providing any advance notice. This change has quite a big impact on API consumers because the client interaction model and API endpoints are completely different between the REST and GraphQL. Thankfully GraphQL still utilises HTTP primitives and returns JSON responses so we at least have a starting point for our new client code.

In this post I am going to look at how you can call a GraphQL API from within an Azure Logic App by using the [in-built HTTP Action](https://docs.microsoft.com/azure/connectors/connectors-native-http).

### Our sample query

For the purpose of this post I am going to use a GraphQL query against the Meetup GraphQL API which uses the predefined [groupByUrlname query](https://www.meetup.com/api/schema/#groupByUrlname) and use it to return the next scheduled event for the specified group. The sample is shown below.

{% gist https://gist.github.com/sjwaight/2ad50310d5485eff107c1973fa657df2 %}

This query shows one of the benefits of GraphQL espoused by its proponents – the ability to send what is effectively two queries (get group AND event details) to the API at once and receive a single response. I must admit this is really handy and helped remove a step in my Logic App.

### Using in a Logic App

As I hinted at above, GraphQL still uses all the usual HTTP primitives, so we can use the [in-built HTTP Action in Logic Apps](https://docs.microsoft.com/azure/connectors/connectors-native-http#add-an-http-action) to call the Meetup GraphQL API.

The Meetup API documentation includes a few samples that show how to call the GraphQL API using [curl](https://curl.se/) which is a really handy way to expose exactly what is required. I’ve included a sample below.

{% gist https://gist.github.com/sjwaight/ec28fc08da1f7d2ff3a4abdbfdeab5e0 %}

The key items of note are:

- Wrap the GraphQL query and any variables in the body of your request as a JSON payload. Specify ‘query’ and ‘variables’ with their own JSON property.
- Set Content-Type to application/json.
- Use the POST HTTP verb.
- The URI to hit is [https://api.meetup.com/gql](https://api.meetup.com/gql).

Given I’m retrieving information on public Meetup groups I don’t need to provide an Authorization token, but apart from that I can use the rest of the curl sample to help me setup my Logic App HTTP Action as shown below.

The response that comes back is in a JSON format which I will parse into an object to make it easier to use elsewhere in my Logic App. The easiest way to build the schema is to run the HTTP Action once, look at the ‘output’ of the Action in the Run, copy the response and then use the “Use sample payload to generate schema” option in the Parse JSON Action.

![Logic App steps for reach API and parse response](https://siliconvalve.files.wordpress.com/2022/03/2022-03-30_10-33-40.png?w=706&h=1024)

In the HTTP Action I am dynamically replacing the URL of the Meetup group with the RowKey from an Azure Storage table. I am doing this because my data design means the RowKey contains the URL component of the meetup group – i.e. “Azure-Sydney-User-Group”.

The net result of this implementation is that my [Meetup-to-Teams bridge](https://blog.siliconvalve.com/2019/05/24/integrate-meetup-announcements-with-microsoft-teams-using-azure-logic-apps-and-adaptive-cards/) is functional again, and in fact is now simplified with only a single Meetup API call. Unfortunately, I can’t use my Custom Connector for the Logic App anymore, but I at least my integration works and I can keep across new meetups as they are announced!

Happy Days! 😎