I am working on creating users on my wiki.js using graphql API and python’s request package. I am able to create a user normally(hard coded) but I want to use variables. Here is the code I tried:
# we have imported the requests module
import requests
# defined a URL variable that we will be
# using to send GET or POST requests to the API
url = "https://wiki.something.com/graphql/"
email = "[email protected]"
name = "Uchiha Sasuke"
body = """
mutation {
users {
create (
email: "{email}"
name: "{name}"
passwordRaw: "pass123$"
providerKey: "local"
groups: [1]
mustChangePassword: true
sendWelcomeEmail: false
) {
responseResult {
succeeded
slug
message
}
user {
id
}
}
}
}
"""
response = requests.post(url=url, json={"query": body}, headers={"Authorization": "Bearer ..."})
print("response status code: ", response.status_code)
if response.status_code == 200:
print("response : ", response.content)
Above code is not working. How should I deal with this? I have taken a look at other questions regarding api and I tried them but it was of no use.
2
perhaps you're looking for
f-strings
. try usingbody = f""" ...........
Oct 3 at 15:30
It did not work for me I tried using that.
Oct 4 at 4:20