Here is what I am using in Python 3:
payload={"query": """query
{
organization(login: "MY-ORG-ID") {
samlIdentityProvider {
externalIdentities(first: 10) {
edges {
node {
user {login}
samlIdentity {nameId}
scimIdentity {username}
}
}
}
}
}
}"""
}
URL = 'https://api.github.com/graphql'
HEADERS = {'accept': 'application/vnd.github.v4.idl', 'authorization': 'bearer MY-GITHUB-TOKEN'}
response = requests.post(url=URL, json=payload, headers=HEADERS)
It just works fine.
However, I am trying to use this query in POSTMAN tool but have no clue how to do this. I tried to remove 3-double quotes """ """
, I get Unexpected 'q'
error. When I use double quotes instead of 3-double quotes and login: \"MY-ORG-ID\"
, I get "message": "Problems parsing JSON"
error.
There's no problem with headers and URL. I just gave them here for completeness.
If you're trying to enter the query into body of your post request in the postman app, a quick workaround to achieve multiple lines is to use a placeholder in the form of an environment variable in your body and enter the query in your pre-request script:
In your body:
{
"query":{{query}}
}
In your pre-request script:
pm.environment.set("query", JSON.stringify(
`
query {
organization(login: "MY-ORG-ID") {
samlIdentityProvider {
externalIdentities(first: 10) {
edges {
node {
user {login}
samlIdentity {nameId}
scimIdentity {username}
}
}
}
}
}
}
`
));
Note that ` in the above code is a backtick, not a single quote!
It's not the best solution ever, but the only one that worked for me so far in Postman to avoid entering more complex queries/mutations in a single line.
Hope this helps.
Postman has a "graphql" type of request body. It means you can write your query without quotes (see screenshot attached). Also, it is useful when you are assigning variables to query/mutation.
P.S. you might need to update your postman to get a "graphql" type of body payload.
Apparently you can't, therefore you need to turn your multiline string into a single string.
Quickest way to do this is to paste it in a web browser search bar for a format change, then copy and paste from the web browser search bar back into postman.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With