Examples on interacting with the GraphQL API¶
Create a new user¶
This will create a new user and return the user information and a token to be used for mutations and queries that require an authenticated user. Keep a copy of the generated token which is good by default for 7 days. After 7 days, you will need to login again to generate another token.
In [1]:
Copied!
import requests
# This is the endpoint for the GraphQL API. On a production installation it might be http://<yourservername>/api .
API_URL = "http://localhost:4000/graphql"
import requests
# This is the endpoint for the GraphQL API. On a production installation it might be http:///api .
API_URL = "http://localhost:4000/graphql"
In [6]:
Copied!
query = """ mutation {
signupUser(login: "dcline", email: "dcline36@mbari.org", password: "cthulhu2") {
token
}
}
"""
reply = (requests.post(API_URL, json={'query': query}).json())
print(f"Your user token it {reply['data']['signupUser']['token']}")
query = """ mutation {
signupUser(login: "dcline", email: "dcline36@mbari.org", password: "cthulhu2") {
token
}
}
"""
reply = (requests.post(API_URL, json={'query': query}).json())
print(f"Your user token it {reply['data']['signupUser']['token']}")
{'data': {'signupUser': {'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjc2LCJpYXQiOjE2NTYwMzU5OTgsImV4cCI6MTY1NjY0MDc5OH0.txOKamf4wo_opFGF77cWJmHpxhjMS1PZNZ6UMH6oAqI'}}}
The returned token can be used in the GraphiQL section REQUEST HEADERS in the Bearer field
Copyright (c) 2022, MBARI