Skip to content

Instantly share code, notes, and snippets.

View tipenehughes's full-sized avatar

Tipene Hughes tipenehughes

View GitHub Profile
@tipenehughes
tipenehughes / verification.py
Created March 2, 2023 20:21
Verifying webhook authenticity
from flask import Flask, request
import hashlib
import hmac
import base64
# Signing secret from webhook itself
SIGNING_SECRET = "{your_signing_secret}"
# Always sha256
SIGNING_SECRET_ALGORITHM = "sha256"
@tipenehughes
tipenehughes / test.js
Created April 20, 2022 17:43
test.js
const test = () => {
console.log("Hello, World!")
}
@tipenehughes
tipenehughes / createOrgMembership.js
Created April 1, 2022 14:01
createOrgMembership
const createOrgMembership = async (res, user, org) => {
const url = `https://${subdomain}.zendesk.com/api/v2/organization_memberships`;
const config = {
method: "POST",
headers: headers,
body: JSON.stringify({
organization_membership: {
organization_id: org.id,
user_id: user.id
}
@tipenehughes
tipenehughes / createOrUpdateUserResponse.js
Created April 1, 2022 14:00
createOrUpdateUserResponse
if (response.ok) {
response.json().then(data => {
console.log("User created/updated");
createOrgMembership(res, data.user, org);
});
} else {
res.status(response.status).send({error:`Cannot create/update user: ${response.statusText}`});
}
};
@tipenehughes
tipenehughes / createOrUpdateUser.js
Created April 1, 2022 14:00
createOrUpdateUser
const createOrUpdateUser = async (req, res, org) => {
const url = `https://${subdomain}.zendesk.com/api/v2/users/create_or_update`;
const config = {
method: "POST",
headers: headers,
body: JSON.stringify({
user: {
email: req.body.email,
name: req.body.name,
verified: true,
if (response.ok) {
response.json().then(data => {
console.log('Org found by name');
// Provides exact matched org name as search API includes non-specific results
const matched_org = data.results.find(({name}) => name === req.body.organization);
createOrUpdateUser(req, res, matched_org);
});
}
const findOrg = async (req, res) => {
const url = `https://${subdomain}.zendesk.com/api/v2/search.json?query=type:organization "${req.body.organization}"`;
const config = {
method: "GET",
headers: headers
};
const response = await fetch(url, config);
@tipenehughes
tipenehughes / createOrUpdateOrgResponse.js
Created April 1, 2022 13:58
createOrUpdateOrgResponse
if (response.ok) {
response.json().then(data => {
console.log('Org created/updated');
createOrUpdateUser(req, res, data.organization);
});
}
else if (response.status===422){
// Find the existing org by name if it already exists
console.log(`Error creating org...${response.status}: ${response.statusText}...finding existing org by name`);
findOrg(req, res);
@tipenehughes
tipenehughes / createOrUpdateOrg.js
Created April 1, 2022 13:56
createOrUpdateOrg()
const createOrUpdateOrg = async (req, res) => {
const url = `https://${subdomain}.zendesk.com/api/v2/organizations/create_or_update`;
const config = {
method: "POST",
headers: headers,
body: JSON.stringify({organization: {name: req.body.organization}})
};
const response = await fetch(url, config);
@tipenehughes
tipenehughes / is_helper.hbs
Last active January 12, 2022 15:35
#is helper
{{#is id 1##### }
<img src="{{asset '2022.png'}}"/>
{{is}}
{{#is id 2##### }
<img src="{{asset '2022.png'}}"/>
{{is}}