Hi, I’m currently running into issues trying to do...
# prefect-community
k
Hi, I’m currently running into issues trying to do a simple get request for logs from the GraphQL API. Could anyone help me identify where my mistake is to get the error below? I’ve tested the query in the Prefect front end’s Interactive API and it works just fine. I’ve also tested in a Javascript get request that that API key works fine, so this may be a requests library related mistake?
k
Can you paste your code here so I can test? I can give it a shot
k
Yes of course:
Copy code
import requests
import json
import pandas as pd

query = """"
query {
  flow_run (
    where: {flow_id: {_eq: "FLOW_ID"}}
    order_by: {state_timestamp: desc}
    limit: 1
  ){
    name
    flow_id
    flow {
      name
      id
    }
    logs {
      message
      created
    }
  }
}
"""

url = "<https://api.prefect.io>"
headers = {"Authorization": "Bearer " + "API_KEY"}

r = requests.get(
  url=url, 
  json=query, 
  headers=headers
)
print(r.text)
k
Use a post request and make your
json
a dict that contains the query:
Copy code
r = <http://requests.post|requests.post>(
  url=url, 
  json=dict(query=query), 
  headers=headers
)
k
I’ve done both and got this error now:
{"errors":[{"message":"Syntax Error: Unterminated string.","extensions":{"code":"GRAPHQL_PARSE_FAILED"}}]}
Did you also adjust the query?
k
oh yeah i was using a simpler query
k
Could you show me what your query looks like?
k
You have an extra ” in the snippet you pasted at the start of the query
k
indeed I do! That worked
Thank you so much!
k
Yep!
k
Very interesting that you have to use a post request, do you know the reason behind that?
k
All GQL are post
k
Ahhh, today I learned!
Thanks again 🙂
👍 1