JavaScript client for Submit JSON written in TypeScript. Works in modern browsers, as well as runtimes like Node.js v18+, Bun, Deno, and Edge Runtime.
If you haven't already, sign up for an account.
Install the client with a package manager:
npm install submitjson # || pnpm add submitjson || yarn add submitjson
Import and create a new client instance
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
endpoint: 'XxXxXxXxX'
})
const data = await sj.submit({
name: 'Yo Yoerson',
message: 'Yo',
powerLevel: 9001,
})
console.log('Submission', data)
submit calls down the line. Pass in default options per client to override the current endpoint settings.interface SubmitJSONConfig {
apiKey: string
secretKey?: string
endpoint?: string
options: SubmitOptions
}
interface SubmitOptions {
emailNotification?: boolean
emailTo?: string
emailReplyTo?: string
emailBranding?: boolean
emailSubject?: string
emailFromName?: string
submissionFormat?: 'pretty' | 'raw'
submissionSound?: 'none' | 'beep' | 'blip' | 'block' | 'coin' | 'ding' | 'dink' | 'honk' | 'jump' | 'ping' | 'pong' | 'snare'
recaptchaToken?: string
turnstileToken?: string
hcaptchaToken?: string
discordNotification?: boolean
slackNotification?: boolean
telegramNotification?: boolean
}
interface SubmissionsQuery {
page?: number
order?: 'asc' | 'desc'
period?: 'day' | 'week' | 'month' | '3months' | '6months' | 'year' | 'all'
search?: string
status?: 'all' | 'new' | 'seen'
}
class SubmitJSON {
constructor(config: SubmitJSONConfig)
// Submission
submit(data, options?, endpoint?): Promise<Submission>
// Endpoints
getEndpoints(query?): Promise<Endpoint[]>
getEndpoint(slug): Promise<EndpointResponse>
getEndpointSubmissions(slug, query?): Promise<SubmissionsResponse>
// Projects
getProjects(query?): Promise<Project[]>
getProject(slug): Promise<ProjectResponse>
getProjectEndpoints(slug): Promise<Endpoint[]>
getProjectSubmissions(slug, query?): Promise<SubmissionsResponse>
// Submissions
getSubmissions(query?): Promise<SubmissionsResponse>
getSubmission(id): Promise<Submission>
deleteSubmission(id): Promise<{ success: boolean }>
}
// ~/submitjson.ts
import SubmitJSON from 'submitjson'
export const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
endpoint: 'XxXxXxXxX',
options: { // set defaults for this client & override endpoint settings
emailNotification: true,
submissionFormat: 'raw',
submissionSound: 'none',
},
})
submit() takes three arguments:string it is treated as the endpoint for submitting dataendpoint.function submit(
data: Record<string, unknown> | string | FormData,
options?: SubmitOptions,
endpoint?: string
): Promise<Submission>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
endpoint: 'XxXxXxXxX',
})
const data = await sj.submit({
name: 'Yo Yoerson',
message: 'Yo',
powerLevel: 9001,
}, {
emailNotification: true,
emailTo: '[email protected]',
emailReplyTo: '[email protected]',
emailBranding: false,
emailSubject: 'My custom subject line',
emailFromName: 'My custom from name',
submissionFormat: 'pretty',
submissionSound: 'ping',
recaptchaToken: 'xxxxxxxxxxx'
}, 'YyYyYyYyY') // overrides the endpoint set in the configuration
console.log('Submission', data)
// submitjson.ts
import SubmitJSON from 'submitjson'
export const contactForm = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
endpoint: 'XxXxXxXxX',
})
export const userSignupNotification = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
endpoint: 'ZzZzZzZzZ',
})
// somewhere else in your code
const data = { name: 'Yo Yoerson', message: 'Yo' }
await contactForm.submit(data)
await userSignupNotification.submit(data)
function getEndpoints(
query?: { sort?: 'name' | 'new' | 'old' | 'submissions' | 'activity' }
): Promise<Endpoint[]>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx', // required for public API routes
})
// Get all endpoints sorted by name (default)
const endpoints = await sj.getEndpoints()
// Get endpoints sorted by most recent submissions
const recentEndpoints = await sj.getEndpoints({ sort: 'activity' })
console.log('Endpoints', endpoints)
function getEndpoint(slug: string): Promise<EndpointResponse>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
const endpoint = await sj.getEndpoint('XxXxXxXxX')
console.log('Endpoint', endpoint.endpoint)
console.log('Webhooks', endpoint.webhooks)
console.log('Origins', endpoint.origins)
function getEndpointSubmissions(
slug: string,
query?: SubmissionsQuery
): Promise<{
submissions: Submission[]
submissionCount: number
totalPages: number
currentPage: number
}>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
// Get first page of submissions
const { submissions, totalPages } = await sj.getEndpointSubmissions('XxXxXxXxX')
// Get new submissions from the last week
const recent = await sj.getEndpointSubmissions('XxXxXxXxX', {
period: 'week',
status: 'new',
order: 'desc',
})
// Search submissions
const results = await sj.getEndpointSubmissions('XxXxXxXxX', {
search: 'urgent',
})
console.log('Submissions', submissions)
function getProjects(
query?: { sort?: 'name' | 'new' | 'old' | 'submissions' | 'activity' }
): Promise<Project[]>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
// Get all projects sorted by name (default)
const projects = await sj.getProjects()
// Get projects sorted by submission count
const busyProjects = await sj.getProjects({ sort: 'submissions' })
console.log('Projects', projects)
function getProject(slug: string): Promise<ProjectResponse>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
const project = await sj.getProject('my-website')
console.log('Project', project.project)
console.log('Endpoints', project.endpoints)
console.log('Slack Workspaces', project.slackWorkspaces)
function getProjectEndpoints(slug: string): Promise<Endpoint[]>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
const endpoints = await sj.getProjectEndpoints('my-website')
console.log('Project Endpoints', endpoints)
function getProjectSubmissions(
slug: string,
query?: SubmissionsQuery
): Promise<{
submissions: Submission[]
submissionCount: number
totalPages: number
currentPage: number
}>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
// Get all submissions for a project
const { submissions } = await sj.getProjectSubmissions('my-website')
// Get unread submissions from the last month
const recent = await sj.getProjectSubmissions('my-website', {
period: 'month',
status: 'new',
page: 1,
})
console.log('Project Submissions', submissions)
function getSubmissions(
query?: SubmissionsQuery & { project?: string }
): Promise<{
submissions: Submission[]
submissionCount: number
totalPages: number
currentPage: number
}>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
// Get all submissions
const { submissions, totalPages } = await sj.getSubmissions()
// Get submissions from a specific project
const projectSubs = await sj.getSubmissions({
project: 'my-website',
})
// Get new submissions from the last day
const today = await sj.getSubmissions({
period: 'day',
status: 'new',
order: 'desc',
})
console.log('All Submissions', submissions)
function getSubmission(id: string): Promise<Submission>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
const submission = await sj.getSubmission('xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
console.log('Submission', submission)
console.log('Submission Data', submission.data)
function deleteSubmission(id: string): Promise<{ success: boolean }>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({
apiKey: 'sjk_xxxxxxxxxxxxxx',
secretKey: 'sjsk_xxxxxxxxxxxxxx',
})
const result = await sj.deleteSubmission('xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
if (result?.success) {
console.log('Submission deleted successfully')
}