Raf*_*fiq 3 python post json postman graphql
这是我在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)
Run Code Online (Sandbox Code Playgroud)
它运作正常.
但是,我试图在POSTMAN工具中使用此查询,但不知道如何执行此操作.我试图删除3双引号""" """,我收到Unexpected 'q'错误.当我使用双引号而不是3双引号时login: \"MY-ORG-ID\",我得到"message": "Problems parsing JSON"错误.
标头和URL没有问题.我刚刚在这里给他们完整性.
Den*_*981 15
如果您尝试在邮递员应用程序中将查询输入到帖子请求的正文中,则实现多行的快速解决方法是在您的身体中使用环境变量形式的占位符并在您的预设中输入查询请求脚本:
在你的身体:
{
"query":{{query}}
}
Run Code Online (Sandbox Code Playgroud)
在您的预请求脚本中:
pm.environment.set("query", JSON.stringify(
`
query {
organization(login: "MY-ORG-ID") {
samlIdentityProvider {
externalIdentities(first: 10) {
edges {
node {
user {login}
samlIdentity {nameId}
scimIdentity {username}
}
}
}
}
}
}
`
));
Run Code Online (Sandbox Code Playgroud)
请注意,上面的代码中的`是反引号,而不是单引号!
它不是有史以来最好的解决方案,但是迄今为止唯一一个在Postman中为我工作以避免在一行中输入更复杂的查询/突变的解决方案.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
5435 次 |
| 最近记录: |