Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Created March 29, 2022 23:29
Show Gist options
  • Save sjwaight/ec28fc08da1f7d2ff3a4abdbfdeab5e0 to your computer and use it in GitHub Desktop.
Save sjwaight/ec28fc08da1f7d2ff3a4abdbfdeab5e0 to your computer and use it in GitHub Desktop.
Bash script showing how to invoke a GraphQL API using curl.
# Originally from: https://www.meetup.com/api/guide/#p02-querying-section
query='query($eventId: ID) {
event(id: $eventId) {
title
description
dateTime
}
}
'
variables='{
"eventId": "276754274"
}'
query="$(echo $query)"
curl -X POST https://api.meetup.com/gql \
-H 'Authorization: Bearer {YOUR_TOKEN}' \
-H 'Content-Type: application/json' \
-d @- <<EOF
{"query": "$query", "variables": "$variables"}
@dskcamer
Copy link

dskcamer commented Dec 7, 2024

#!/bin/bash

URL de l'API GraphQL

API_URL="https://api.meetup.com/gql"

Token d'autorisation (remplacez YOUR_TOKEN par votre vrai token)

AUTH_TOKEN="YOUR_TOKEN"

Définition de la requête GraphQL

query='
query ($eventId: ID) {
event(id: $eventId) {
title
description
dateTime
}
}
'

Variables pour la requête

variables='{
"eventId": "276754274"
}'

Utilisation de curl pour appeler l'API GraphQL

curl -X POST "$API_URL"
-H "Authorization: Bearer $AUTH_TOKEN"
-H "Content-Type: application/json"
-d "$(jq -n --arg query "$query" --argjson variables "$variables"
'{query: $query, variables: $variables}')"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment