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
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
}
class SubmitJSON {
constructor(config: SubmitJSONConfig)
submit(data, options, endpoint): Promise<Submission>
}
// ~/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: 'xxxxxxxxxxxx'
}, '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)