Send an application from an AI agent
Talks, written cases and partnership enquiries are open.
- Paste the function into a JavaScript tool in your agent (Node.js 24 works).
- Read the current status and policy versions. Show the user the full draft and the Privacy Notice. For a case, ask them to accept the Submission Terms.
- Set
approval.confirmedonly after the user approves the draft and asks to send it. Pass the versions they reviewed asapproval.privacyNoticeVersionand, for cases,approval.submissionTermsVersion. - Set
input.kindtocaseorpartner, put the fields below ininput.applicationand generate aninput.idempotencyKeywithcrypto.randomUUID(). Return the application reference to the user.
export async function submitMarketingWeekendApplication(input, approval) {
const { kind, application, idempotencyKey, retry } = input;
if (kind !== 'case' && kind !== 'partner') throw new Error('Choose case or partner.');
if (approval?.confirmed !== true) throw new Error('Show the user the application and get their approval before submitting.');
if (!/^[A-Za-z0-9_-]{16,128}$/u.test(idempotencyKey ?? '')) throw new Error('Supply a stable idempotency key for this application.');
const base = 'https://marketingweekend.com';
const options = () => ({ redirect: 'error', signal: AbortSignal.timeout(15000) });
const statusResponse = await fetch(base + '/api/applications/status', options());
if (!statusResponse.ok) throw new Error('Could not check if applications are open.');
const status = await statusResponse.json();
if (!status.open) return { submitted: false, reason: 'intake_closed', next: status.forms[kind] };
const policiesMatch = approval.privacyNoticeVersion === status.privacy_notice_version &&
(kind !== 'case' || approval.submissionTermsVersion === status.submission_terms_version);
if (!policiesMatch && retry !== true) {
return { submitted: false, reason: 'policy_changed', privacyNotice: status.privacy_notice, submissionTerms: status.submission_terms };
}
const payload = { ...application, source: 'agent', privacyNoticeVersion: approval.privacyNoticeVersion };
if (kind === 'case') {
payload.submissionTermsVersion = approval.submissionTermsVersion;
payload.termsAccepted = true;
payload.newsletter = false;
}
const response = await fetch(base + '/api/applications/' + kind, {
...options(),
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Idempotency-Key': idempotencyKey },
body: JSON.stringify(payload)
});
const result = await response.json().catch(() => ({}));
if (result.error === 'legal_version_changed') {
return { submitted: false, reason: 'policy_changed', privacyNotice: status.privacy_notice, submissionTerms: status.submission_terms };
}
return response.ok && result.applicationId
? { submitted: true, applicationId: result.applicationId }
: { submitted: false, status: response.status, error: result.error ?? 'unexpected_response', fields: result.fields, retryAfter: response.headers.get('Retry-After') };
}
If the first response was lost, retry with input.retry = true, the original key, the same fields and the policy versions the user approved.
- Case fields
fullName,email,roleCompany,format(talk,written_caseoreither),track(marketing,ecommerceorboth),titleandsummary. Fortalkoreither, addpresentationLanguage(englishordiscuss).- Partnership fields
contactName,email,company,website,contributionandinterests(an array with one or more offinancial,case,tools,technology,community).