How to place a multi-line single string JSON in POSTMAN?

Viewed 29540

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.

4 Answers

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.

screenshot from Postman UI with "graphql" radio button

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.

Triple quotes in Python denote a multi-line string right? So try double quotes, and login: \"MY-ORG-ID\" and placing the entire query in a single line?

 {
   "query":"query{organization(login: \"MY-ORG-ID\") {samlIdentityProvider {externalIdentities(first: 10) {edges {node {user {login}samlIdentity {nameId}scimIdentity {username}}}}}}}"
 }
Related