* fix timezone display on booking page to reflect event availability timezone * migrate fetching event owner's schedule to server side * migrate fetching event owner's schedule to server side * fix e2e test errors * Add WEBAPP_URL_FOR_OAUTH to salesforce auth * In event manager constructor include "_crm" credentials as calendar creds * Change crm apps to type to end with `_crm` * Move sendgrid out of CRM * Add zoho bigin to CRM apps * When getting apps, use slug * Add `crm` variants * Hubspot Oauth use `WEBAPP_URL_FOR_OAUTH` * Refactor creating credentials * Fix empty CRM page * Use credentials with `_crm` * Abstract getAppCategoryTitle * Add integration.handler changes * Fix tests * Type fix --------- Co-authored-by: Shaik-Sirajuddin <sirajuddinshaik30gmail.com> Co-authored-by: Shaik-Sirajuddin <sirajudddinshaik30@gmail.com> Co-authored-by: Shaik-Sirajuddin <89742297+Shaik-Sirajuddin@users.noreply.github.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import * as hubspot from "@hubspot/api-client";
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { WEBAPP_URL_FOR_OAUTH } from "@calcom/lib/constants";
|
|
|
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
|
import { encodeOAuthState } from "../../_utils/oauth/encodeOAuthState";
|
|
|
|
const scopes = ["crm.objects.contacts.read", "crm.objects.contacts.write"];
|
|
|
|
let client_id = "";
|
|
const hubspotClient = new hubspot.Client();
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
if (req.method !== "GET") return res.status(405).json({ message: "Method not allowed" });
|
|
|
|
const appKeys = await getAppKeysFromSlug("hubspot");
|
|
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
|
|
if (!client_id) return res.status(400).json({ message: "HubSpot client id missing." });
|
|
|
|
const redirectUri = `${WEBAPP_URL_FOR_OAUTH}/api/integrations/hubspot/callback`;
|
|
const url = hubspotClient.oauth.getAuthorizationUrl(
|
|
client_id,
|
|
redirectUri,
|
|
scopes.join(" "),
|
|
undefined,
|
|
encodeOAuthState(req)
|
|
);
|
|
res.status(200).json({ url });
|
|
}
|