Unlock the full potential of your online courses! Learn step-by-step how to integrate v0 with Teachable and enhance your teaching platform today.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
teachableIntegration.ts
in your project’s main folder.
export class TeachableClient {
private apiKey: string;
private baseUrl: string = 'https://your-teachable-domain.com/api/v1';
constructor(apiKey: string) {
this.apiKey = apiKey;
}
async enrollStudent(courseId: string, studentId: string): Promise {
const url = ${this.baseUrl}/courses/${courseId}/enrollments;
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': Bearer ${this.apiKey}
},
body: JSON.stringify({ student_id: studentId })
});
return await response.json();
} catch (error) {
console.error('Error enrolling student:', error);
throw error;
}
}
}
config.ts
in your project’s main folder.config.ts
:
export const TEACHABLEAPIKEY = 'your-teachable-api-key-here';
export const TEACHABLECOURSEID = 'your-teachable-course-id-here';
'your-teachable-api-key-here'
and 'your-teachable-course-id-here'
with your actual credentials from Teachable.
main.ts
) where you initialize or run your application’s code.
import { TeachableClient } from './teachableIntegration';
import { TEACHABLEAPIKEY, TEACHABLECOURSEID } from './config';
const teachable = new TeachableClient(TEACHABLEAPIKEY);
main.ts
:
async function enrollStudentToTeachable(studentId: string) {
try {
const result = await teachable.enrollStudent(TEACHABLECOURSEID, studentId);
console.log('Enrollment Successful:', result);
} catch (error) {
console.error('Enrollment Failed:', error);
}
}
// Example usage: Enroll a test student with ID 'student123'
enrollStudentToTeachable('student123');
'student123'
with the actual student ID when needed.
fetch
(for example, if running in Node.js), you may add a fetch polyfill directly in your code by inserting the following snippet at the very beginning of your main.ts
file:
// If running in Node.js, uncomment the lines below to import a fetch polyfill from a CDN.
// Otherwise, if the browser environment already supports fetch, you can ignore this section.
// import('https://cdn.jsdelivr.net/npm/[email protected]/dist/node-fetch.min.js').then(module => {
// // @ts-ignore
// global.fetch = module.default;
// });
teachableIntegration.ts
, config.ts
, and modifications in main.ts
), reload your application in the browser or the environment where your project runs.Enrollment Successful:
followed by the response from Teachable’s API.Enrollment Failed:
messages and review your API credentials and course ID.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.