Guide

Create ezcaldev account#

First you'll need a ezcaldev account which you can get here once you verify your email, you'll be able to use your credentials to get an authtoken to be used with the api calls.

Get an authtoken#

In order to interact with the calender api endpoint you'll need to supply an Authorization token ( supplied in the auth-token header of the login response)

lets login.

const fetch = require("node-fetch");
async function ezcaldevLogin(uid, pwd) {
const response = await fetch("https://auth.ezcaldev.com/api/Login", {
method: "post",
body: JSON.stringify({ email: uid, password: pwd }),
headers: { "Content-Type": "application/json" },
});
const data = await response.json();
return { token: response.headers.get("auth-token"), message: data.message };
}
(async () => {
try {
console.log(await ezcaldevLogin("youremail", "yourpassword")).token;
} catch (e) {
// Deal with the fact the chain failed
}
})();

the response will contains a header named auth-token copy it's value into the Authorization header of your graphql requests.

Create a calendar#

const axios = require("axios");
const graphql = require("graphql");
const { print } = graphql;
const gql = require("graphql-tag");
const createOrUpdateCalendarGQL = gql`
mutation createOrUpdateCalendar($id: String!) {
createOrUpdateCalendar(calendarId: $id) {
id
events {
id
title
body
state(calendarId: $id)
}
}
}
`;
const API_URL = "https://app-sandbox.ezcaldev.com/api/graphql";
const CALENDAR_ID = "my-first-calendar";
async function callEzCalDev({ query, variables, authCode }) {
return axios({
url: API_URL,
method: "post",
// Note you will have to pass in your authCode for your own account
// headers: {
// Authorization: authCode,
// },
data: {
query: print(query),
variables,
},
});
}
async function createOrUpdateCalendar({ id }) {
const graphqlData = await callEzCalDev({
query: createOrUpdateCalendarGQL,
variables: { id },
});
console.log("api response data", JSON.stringify(graphqlData.data));
const calendar = graphqlData.data.data.createOrUpdateCalendar;
return calendar;
}
(async () => {
try {
const res = await createOrUpdateCalendar({ id: CALENDAR_ID });
} catch (e) {
console.log("error", e);
}
})();
}

Create an event#

const axios = require("axios");
const graphql = require("graphql");
const { print } = graphql;
const gql = require("graphql-tag");
const createOrUpdateEventGQL = gql`
mutation createOrUpdateEvent(
$eventId: String!
$calendarId: String!
$startAt: String!
$endAt: String!
$title: String
$body: String
) {
createOrUpdateEvent(
eventId: $eventId
calendarId: $calendarId
startAt: $startAt
endAt: $endAt
title: $title
body: $body
) {
id
}
}
`;
const API_URL = "https://app-sandbox.ezcaldev.com/api/graphql";
async function callEzCalDev({ query, variables, authCode }) {
return axios({
url: API_URL,
method: "post",
// Note you will have to pass in your authCode for your own account
// headers: {
// Authorization: authCode,
// },
data: {
query: print(query),
variables,
},
});
}
async function createOrUpdateEvent(eventData) {
const graphqlData = await callEzCalDev({
query: createOrUpdateEventGQL,
variables: { ...eventData },
});
console.log("api response data", JSON.stringify(graphqlData.data));
const event = graphqlData.data.data.createOrUpdateCalendar;
return event;
}
(async () => {
try {
let eventData = {
eventId: "my-first-event",
calendarId: "my-first-calendar",
startAt: "2021-12-19T22:40:06Z",
endAt: "2021-12-20T22:40:06Z",
title: "team kickoff event",
body: "our team is awesome!",
};
const res = await createOrUpdateEvent(eventData);
} catch (e) {
console.log("error", e);
}
})();

Accept an Event#

const axios = require("axios");
const graphql = require("graphql");
const { print } = graphql;
const gql = require("graphql-tag");
const acceptInviteGQL = gql`
mutation acceptInvite($eventId: String!, $calendarId: String!) {
acceptInvite(eventId: $eventId, calendarId: $calendarId) {
id
title
body
}
}
`;
const API_URL = "https://app-sandbox.ezcaldev.com/api/graphql";
async function callEzCalDev({ query, variables, authCode }) {
return axios({
url: API_URL,
method: "post",
// Note you will have to pass in your authCode for your own account
// headers: {
// Authorization: authCode,
// },
data: {
query: print(query),
variables,
},
});
}
async function acceptEvent(eventData) {
const graphqlData = await callEzCalDev({
query: acceptInviteGQL,
variables: { ...eventData },
});
console.log("api response data", JSON.stringify(graphqlData.data));
const event = graphqlData.data.data.createOrUpdateCalendar;
return event;
}
(async () => {
try {
let eventData = {
eventId: "my-first-event",
calendarId: "my-first-user-calendar",
};
const res = await acceptEvent(eventData);
} catch (e) {
console.log("error", e);
}
})();