Template Content
About the template
About ScriptRunner Connect
What is ScriptRunner Connect?
Can I try it out for free?
Yes. ScriptRunner Connect comes with a forever free tier.
Can I customize the integration logic?
Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.
Can I change the integration to communicate with additional apps?
Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.
What if I don't feel comfortable making changes to the code?
First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.
Do I have to host it myself?
No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.
What about security?
ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.
Template Content
This template demonstrates how to manually implement OAuth 2.0 flow for Zendesk.
Async HTTP Event
Listener and then fill out necessary parameters in Parameters
, including the URL you received from the Event Listener.CreateAuthLink
script, copy authorization URL from console. ClearStorage
script. Keep in mind that you'll have to go through setup process all over again after that.Run MakeAPIRequest
script to test the connection.
import { RecordStorage } from '@sr-connect/record-storage';
export default async function (event: any, context: Context): Promise<void> {
const storage = new RecordStorage({ secure: true });
await storage.deleteValue('access_token');
console.log('All values deleted from Record Storage.');
}
import { RecordStorage } from '@sr-connect/record-storage';
import { EnvVars } from './Types';
export default async function (event: any, context: Context): Promise<void> {
const { CALLBACK_URL, CLIENT_ID, INSTANCE_NAME, SCOPES } = context.environment.vars as EnvVars;
// Set up encrypted Record Storage
const storage = new RecordStorage({ secure: true });
// URL that will be printed to copy to the new tab
const url = `https://${INSTANCE_NAME}.zendesk.com/oauth/authorizations/new?response_type=code&redirect_uri=${encodeURIComponent(CALLBACK_URL)}&client_id=${encodeURIComponent(CLIENT_ID)}&scope=${encodeURIComponent(SCOPES.join(' '))}`;
console.log('Copy the url and open in a different tab:');
console.log(url);
}
import { HttpEventRequest } from '@sr-connect/generic-app/events/http';
import { RecordStorage } from '@sr-connect/record-storage';
import { EnvVars } from './Types';
export default async function (event: HttpEventRequest, context: Context): Promise<void> {
if (context.triggerType === 'MANUAL') {
console.error('This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.');
return;
}
const { CALLBACK_URL, CLIENT_ID, CLIENT_SECRET, INSTANCE_NAME, SCOPES } = context.environment.vars as EnvVars;
const code = event.queryStringParams.code;
// Check if code query param is included in response
if (!code) {
throw new Error('No code in event payload.');
}
const storage = new RecordStorage({ secure: true });
// Request access token
const response = await fetch(`https://${INSTANCE_NAME}.zendesk.com/oauth/tokens`, {
method: 'POST',
body: JSON.stringify({
grant_type: 'authorization_code',
code,
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
redirect_uri: CALLBACK_URL,
scope: SCOPES.join(' ')
}),
});
if (!response.ok) {
throw new Error('Failed to get access token.');
}
const parsedResponse: { access_token: string } = await response.json();
if (!parsedResponse.access_token) {
throw new Error('No access token in response.');
}
// Save access token in Record Storage
storage.setValue('access_token', parsedResponse.access_token);
console.log('Access token saved in Record Storage.');
}
import { RecordStorage } from '@sr-connect/record-storage';
import { EnvVars } from './Types';
export default async function (event: any, context: Context): Promise<void> {
const { INSTANCE_NAME } = context.environment.vars as EnvVars;
const storage = new RecordStorage({ secure: true });
const token = await storage.getValue('access_token');
// Make request with Zendesk API
const response = await fetch(`https://${INSTANCE_NAME}.zendesk.com/api/v2/tickets.json`, {
headers: {
'Authorization': `Bearer ${token}`
}
});
if (!response.ok) {
throw new Error('Failed to make API request.');
}
console.log(await response.json());
}
export interface EnvVars {
readonly CALLBACK_URL: string;
readonly CLIENT_ID: string;
readonly CLIENT_SECRET: string;
readonly INSTANCE_NAME: string;
readonly SCOPES: string[];
}