-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_fetch.sh
executable file
·24 lines (20 loc) · 988 Bytes
/
1_fetch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
# Fetch data from The Graph API and store it in data.json
# Load environment variables from .env file
if [ -f .env ]; then
export $(cat .env | xargs)
fi
API_ENDPOINT="https://gateway-arbitrum.network.thegraph.com/api/${THEGRAPH_API_KEY}/deployments/id/QmevWPSB6PYKWrQCfD52nNtgYoFN4cRA3Dq2MjMjyu9Q9L"
QUERY='{"query":"{litems(where:{registry:\"0xae6aaed5434244be3699c56e7ebc828194f26dc3\"}){itemID status key0 key1 key2}}"}'
DATA_FILE="data.json"
# Use curl to execute GraphQL query
RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" -d "$QUERY" $API_ENDPOINT)
HTTP_CODE=$(echo $RESPONSE | jq -r 'if .errors then "400" else "200" end')
echo "HTTP Status Code: $HTTP_CODE"
if [[ "$HTTP_CODE" != "200" ]]; then
echo "Error detected:" $(echo $RESPONSE | jq '.errors[].message') | tee -a error_log.txt
exit 1
else
PARSED_RESPONSE=$(echo $RESPONSE | jq '[.data.litems[] | {url: .key0, commit: .key1, chainId: .key2}]')
echo $PARSED_RESPONSE > $DATA_FILE
fi