Back to Marketing Weekend

Send an application from an AI agent

Talks, written cases and partnership enquiries are open.

Download JavaScript
  1. Paste the function into a JavaScript tool in your agent (Node.js 24 works).
  2. 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.
  3. Set approval.confirmed only after the user approves the draft and asks to send it. Pass the versions they reviewed as approval.privacyNoticeVersion and, for cases, approval.submissionTermsVersion.
  4. Set input.kind to case or partner, put the fields below in input.application and generate an input.idempotencyKey with crypto.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_case or either), track (marketing, ecommerce or both), title and summary. For talk or either, add presentationLanguage (english or discuss).
Partnership fields
contactName, email, company, website, contribution and interests (an array with one or more of financial, case, tools, technology, community).