Making Your First Requests
Welcome to the Quick Start Guide for the Semble GraphQL Public API. This guide will help you make your first GraphQL requests to our API by showcasing practical examples in cURL, JavaScript, and Python.
Step 1: Setup
Before you can send requests, you'll need to set up your environment:
Install cURL, a widely-used command-line tool for sending HTTP requests.
If you're using JavaScript, make sure you have
node-fetch
installed. Usenpm install node-fetch
if not.For Python users, ensure you have the
requests
library. If it's not installed, you can add it withpip install requests
.Obtain an authentication token:
- For token authentication, generate a token in the Semble application's settings section.
Step 2: Fetching Patient Data
We're going to make a request to the patient
query to fetch a patient's firstName
and email
.
- curl
- Javascript
- Python
curl -X POST https://open.semble.io/graphql \
-H "Content-Type: application/json" \
-H "x-token: yourtoken" \
-d '{
"query": "query { patient(id: \"1\") { firstName email } }"
}'
const fetch = require('node-fetch');
const query = `
query {
patient(id: "1") {
firstName
email
}
}
`;
fetch('https://open.semble.io/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-token': 'yourtoken',
},
body: JSON.stringify({ query }),
})
.then((res) => res.json())
.then((res) => console.log(res.data));
import requests
import json
query = """
query {
patient(id: "1") {
firstName
email
}
}
"""
headers = {
'Content-Type': 'application/json',
'x-token': 'yourtoken',
}
response = requests.post(
'https://open.semble.io/graphql',
headers=headers,
data=json.dumps({"query": query})
)
print(response.json())
Replace yourtoken
and id
with your actual token and patient ID.
Step 3: Adding a Label to a Patient
Next, we're going to add a label to a patient using the addPatientLabel
mutation. The mutation takes two parameters: patientId
and labelReferenceId
.
- curl
- Javascript
- Python
curl -X POST https://open.semble.io/graphql \
-H "Content-Type: application/json" \
-H "x-token: yourtoken" \
-d '{
"query": "mutation addPatientLabel($patientId: ID!, $labelReferenceId: ID!) { addPatientLabel(patientId: $patientId, labelReferenceId: $labelReferenceId) { data { id } error } }",
"variables": {"patientId": "1", "labelReferenceId": "1"}
}'
const fetch = require('node-fetch');
const mutation = `
mutation addPatientLabel($patientId: ID!, $labelReferenceId: ID!) {
addPatientLabel(patientId: $patientId, labelReferenceId: $labelReferenceId) {
data {
id
}
error
}
}
`;
const variables = {
patientId: '1',
labelReferenceId: '1',
};
fetch('https://open.semble.io/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-token': 'yourtoken',
},
body: JSON.stringify({ query: mutation, variables }),
})
.then((res) => res.json())
.then((res) => console.log(res.data));
import requests
import json
mutation = """
mutation addPatientLabel($patientId: ID!, $labelReferenceId: ID!) {
addPatientLabel(patientId: $patientId, labelReferenceId: $labelReferenceId) {
data {
id
}
error
}
}
"""
variables = {
"patientId": "1",
"labelReferenceId": "1"
}
headers = {
'Content-Type': 'application/json',
'x-token': 'yourtoken',
}
response = requests.post(
'https://open.semble.io/graphql',
headers=headers,
data=json.dumps({"query": mutation, "variables": variables})
)
print(response.json())
Replace yourtoken
, patientId
, and labelReferenceId
with your actual token, patient ID, and label reference ID.
Step 4: Exploring Further
Congratulations on making your first requests to the Semble GraphQL Public API! Once you're comfortable with these basics, feel free to explore more complex queries and mutations. The Semble GraphQL Public API provides a rich set of features that can help you build robust and efficient applications.
Remember to refer to our detailed API Reference section for comprehensive information about all available queries, mutations, and subscriptions.
Troubleshooting
If you encounter any issues, please reach out to our integrations team. Happy coding!