Conjure
Search…
API Quick Start Guide
Conjure's GraphQL API is available to all users and several apps and hacks built off it, using both OAuth applications and personal access tokens.
Proper documentation is coming, but here is a guide to get you up and running with personal access tokens.
As Conjure's has a GraphQL API, you can view the generated documentation using an appropriate client, such as Insomnia. Go ahead and download it from that link and open it up.
Start off a new blank workspace and click the "New Request" button.
Select the "POST" method and select "GraphQL Query" for body, then smash that "Create" button.
Set the URL to "https://api.conjure.so/graphql", then click the "Schema" button, then on the dropdown press "Refresh Schema".
Once the schema is finished refreshing, the "Show Documentation" button will become enabled, go ahead and click it.
Now on the right side bar, you will see the GraphQL API documentation. You can click the orange link text to drill down into the different queries (reading data), mutations (writing data) and various data types.
We'll list your habits now, first off we need a Personal Access Token in order to authenticate the requests, to do this in Conjure go to "Settings" and then "API" (link). Create a Personal Access Token and copy the resulting access token (it'll only be shown that one time, so note it properly).
Go back to Insomnia, click the "Header" tab and add a new header "Authorization" with a value of "Bearer YOUR_ACCESS_TOKEN"
Now, click on the "GraphQL" tab. We can click on the documentation on right side bar to see what fields a Habit query returns, and compose our query.
You can see the name of the query 'habits' and the various fields it returns. Paste the below snipper into the body area of the request and click "Send"
1
query {
2
habits {
3
id
4
name
5
position
6
confetti
7
recurrenceRule
8
streak {
9
id
10
count
11
endedAt
12
}
13
}
14
}
Copied!
Great! We now have our habits!
Now lets say we want to create a measurement for a Timestamp Measure.
Go to the Measure in Conjure and click it, you can find it's ID in the URL (eg in "https://conjure.so/measures/21" the ID is "21"). To a create a measurement, paste the following snippet in the body area and click "Send". The time value is in ISO8601 format and you can see the fields we want returned (success, errors, the created timestamp measurement).
1
mutation {
2
measurementTimestampCreate(input: {
3
measureId: "21",
4
attributes: {
5
value: "2021-04-15T11:20:52.000+01:00",
6
comment: "Hello API! From Insomnia!"
7
}
8
}){
9
success
10
errors {
11
fullMessages
12
}
13
measurementTimestamp {
14
id
15
value
16
comment
17
}
18
}
19
}
Copied!
Here is a video demoing the request and showing you how to find the input attributes and the available fields for return, along with the auto complete that makes life so much easier.
An alternative approach, is just to copy a request the web app makes and tweak it.
Go to a measure in the web app, click "New Timestamp" to show the form dialog, then right click the page and click "Inspect" to show the Chrome Web Inspector. Click the "Network" tab in order to be able to see the request when the web app makes it.
Click the "Create" button and you will see a new request, click it to open the request information in a right side bar and scroll down to "Request Payload" to see what was sent.
Click "view source" to see the request body as JSON.
Highlight and copy the JSON request payload (you can format it nicely with JSONLint to make it more readable). Go back to Insomnia, click the "GraphQL" tab and select "JSON" from the dropdown, now paste the copied JSON request payload into the body area and edit the values accordingly.
1
{
2
"operationName": "measurementTimestampCreate",
3
"variables": {
4
"input": {
5
"measureId": "21",
6
"attributes": {
7
"value": "2021-04-15T11:20:52.000+01:00",
8
"comment": "Hello API! From Insomnia!"
9
}
10
}
11
},
12
"query": "mutation measurementTimestampCreate($input: MeasurementTimestampCreateMutationInput!) {\n measurementTimestampCreate(input: $input) {\n success\n errors {\n ...ValidationErrorsFields\n __typename\n }\n measurementTimestamp {\n ...MeasurementTimestampFields\n __typename\n }\n __typename\n }\n}\n\nfragment ValidationErrorsFields on ValidationErrors {\n messages {\n attribute\n messages\n __typename\n }\n fullMessages\n __typename\n}\n\nfragment MeasurementTimestampFields on MeasurementTimestamp {\n id\n comment\n value\n __typename\n}\n"
13
}
Copied!
This approach can be copied for any action in the Conjure web app (eg creating a new time entry from the Time view).
Here is a Javascript snippet to create a measurement, that uses code obtained in the above fashion:
1
var accessToken = "YOUR_ACCESS_TOKEN";
2
var measureId = "228";
3
var value = new Date().toISOString();
4
var comment = "JS Snippet";
5
6
fetch("https://backend.conjure.so/graphql", {
7
"headers": {
8
"authorization": "Bearer "+accessToken,
9
"content-type": "application/json",
10
},
11
"body": "{\"operationName\":\"measurementTimestampCreate\",\"variables\":{\"input\":{\"measureId\":\""+measureId+"\",\"attributes\":{\"value\":\""+value+"\",\"comment\":\""+comment+"\"}}},\"query\":\"mutation measurementTimestampCreate($input: MeasurementTimestampCreateMutationInput!) {\\n measurementTimestampCreate(input: $input) {\\n success\\n errors {\\n ...ValidationErrorsFields\\n __typename\\n }\\n measurementTimestamp {\\n ...MeasurementTimestampFields\\n __typename\\n }\\n __typename\\n }\\n}\\n\\nfragment ValidationErrorsFields on ValidationErrors {\\n messages {\\n attribute\\n messages\\n __typename\\n }\\n fullMessages\\n __typename\\n}\\n\\nfragment MeasurementTimestampFields on MeasurementTimestamp {\\n id\\n comment\\n value\\n __typename\\n}\\n\"}",
12
"method": "POST"
13
}).then(response => {
14
console.log("✅");
15
console.log(response);
16
}).catch(error => {
17
console.log("❌");
18
console.log(error);
19
});
Copied!
With the Chrome Web Inspector, you can right click the request also and copy it for JS (fetch), cURL or others, to get generated code, which you can then tweak.
This has been a brief guide, potentially introducing several new concepts, if you get stuck, feel free to reach out over the "Feedback" button in Conjure! Happy hacking 🎉
Last modified 5mo ago
Copy link