import {z} from 'zod' export type CreateApiSignupArgs = {'Account-ID': string, body: {email: string, uid?: string | undefined, tid?: string | undefined, ref_id?: string | undefined, ip?: string | undefined, created_at?: string | undefined, skip_email_notification?: boolean | undefined} | {email?: string | undefined, uid: string, tid?: string | undefined, ref_id?: string | undefined, ip?: string | undefined, created_at?: string | undefined, skip_email_notification?: boolean | undefined}}; export type CreateApiSignupOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiSignupResponse = z.object({id: z.number().int().optional(), etype: z.string().optional(), sale_amount: z.number().int().nullable().optional(), original_sale_amount: z.number().int().nullable().optional(), original_sale_currency: z.string().nullable().optional(), event_id: z.string().nullable().optional(), plan_id: z.string().nullable().optional(), billing_period: z.string().nullable().optional(), created_at: z.string().optional(), referral: z.object({id: z.number().int().optional(), email: z.string().optional(), uid: z.string().nullable().optional()}).optional(), commissions: z.array(z.unknown()).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Capture a lead when they sign-up or fill an optin form. This endpoint is used to track leads and sign-ups. It's not for tracking the actual sales and commissions.

Sign-ups are tracked as leads in FirstPromoter so when a person referred by the promoter/affiliate signs up, a new referral should be added inside FirstPromoter **(you can see them inside the `Referrals` section as `Leads`)**.

The recommended way to do this is to grab the `_fprom_tid` **(_fprom_track for accounts created prior to April 2021)** cookie value(which keeps the tracking id and referral identification) on your server and send it along with the sign-up data through the tid parameter.

**Alternative:** In some special cases, you can refer sign ups directly to a promoter, by passing the referral id through ref_id parameter. Be careful when using this because the referral id can be modified by the promoter by default, however you can disable that from the campaign configuration page.
**HTTP Request**
`POST https://api.firstpromoter.com/api/v2/track/signup`
* * POST /signup */ export const createApiSignup = async (args: CreateApiSignupArgs, options?: CreateApiSignupOptions) => { const {baseUrl = "https://api.firstpromoter.com/api/v2/company", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Account-ID'] != null) headers.set("Account-ID", String(args['Account-ID'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/signup${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiSignupResponse, await res.json()) };