Skip to content

Instantly share code, notes, and snippets.

@eduwass
Last active September 5, 2022 08:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduwass/bd05de0610d2b3e168605b4f1c431543 to your computer and use it in GitHub Desktop.
Save eduwass/bd05de0610d2b3e168605b4f1c431543 to your computer and use it in GitHub Desktop.
Rize → Conjure

Connect Rize data with Conjure

The general idea is that this will run as a task at the end of a day, which will copy the following measures from Rize to Conjure for that day:

  • workHours
  • trackedTime
  • focusTime
  • meetingTime
  • breakTime

I used Pipedream for convenience, but with general Javascript knowledge you should also be able to easily use this outside of it.

Steps

  1. Create a workflow in Pipedream
  2. Use a cron trigger to run periodically (I make it run daily, at the end of the day)
  3. Add Node.js code step and paste code of workflow.js

CleanShot 2022-09-01 at 12 52 15@2x

  1. Make sure to have ENV vars in Pipedream:
    • RIZE_ACCESS_TOKEN (get values from devtools like this )
    • RIZE_CLIENT
    • RIZE_UID
    • CONJURE_TOKEN (generate here )
  2. Create each measure in Conjure.so and update the conjureMeaures bit of the code with your specific measure IDs:
    // You need to have created these measures in Conjure.so!
    // Measure Type = Time Entry.
    const conjureMeasures = { 
      workHours: 'meas_PEpOo2wPuYIayt',
      trackedTime: 'meas_YUFIKHuM7xu6pn',
      focusTime: 'meas_eojMpWxI2wcFQT',
      meetingTime: 'meas_g35McMEtmUuHGd',
      breakTime: 'meas_JjQOUldQkbbx0D'
    }
  1. That's it, now when the workflow runs, watch the logs to verify that values made it to Conjure.

CleanShot 2022-09-01 at 23 55 44

// To use any npm package on Pipedream, just import it
import moment from 'moment';
import axios from "axios";
export default defineComponent({
async run({ steps, $ }) {
const today = moment( new Date() ).format("YYYY-MM-DD");
console.log('🔆 Getting data for date: ' + today)
const data = await getRizeWorkHours(today);
console.log('⏰ Data received:', data);
// You need to have created these measures in Conjure.so!
// Measure Type = Time Entry.
const conjureMeasures = {
workHours: 'meas_PEpOo2wPuYIayt',
trackedTime: 'meas_YUFIKHuM7xu6pn',
focusTime: 'meas_eojMpWxI2wcFQT',
meetingTime: 'meas_g35McMEtmUuHGd',
breakTime: 'meas_JjQOUldQkbbx0D'
}
await createConjureMeasurements( today, data, conjureMeasures );
return data
},
})
async function getRizeWorkHours(datetime){
// this request was copied from rize devtools like this: https://share.cleanshot.com/NiMyHI
const options = {
method: 'POST',
url: 'https://api.rize.io/v1/graphql',
headers: {
'Content-Type': 'application/json',
'access-token': process.env.RIZE_ACCESS_TOKEN,
'client': process.env.RIZE_CLIENT,
'uid': process.env.RIZE_UID
},
data: {
'operationName': 'WorkHours',
'variables': '{ "date": "'+datetime +'" }',
'query': "query WorkHours($date: String!) { workHours(date: $date) { workHours trackedTime focusTime meetingTime breakTime } }",
}
};
let responseData = await axios.request(options);
return responseData.data.data.workHours;
}
async function createMeasure(measurementId, measurementTimestamp, measurementValue, measurementComment){
const options = {
method: 'POST',
url: 'https://api.conjure.so/graphql',
headers: {
'Authorization': 'Bearer ' + process.env.CONJURE_TOKEN,
'Content-Type': 'application/json'
},
data: {
"query": "mutation{ measurementCreate( input:{ measureId: \""+measurementId+"\", attributes: { timestamp: \""+measurementTimestamp+"\", comment: \""+measurementComment+"\", values: { active: false, duration: "+measurementValue+" } } } ) { success }}"
}
};
let responseData = await axios.request(options)
return responseData.data;
}
async function createConjureMeasurements( today, data, measures ){
for(const currentMeasure in measures){
const measurementId = measures[currentMeasure];
const measurementTimestamp = today;
const measurementValue = data[currentMeasure];
const measurementComment = '🤖 Programatically adding ' + currentMeasure + ' of ' + today;
const measure = await createMeasure(measurementId, measurementTimestamp, measurementValue, measurementComment);
console.log(measurementComment, measure);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment