fastify-xwhatconverts
leads.create
Create a new WhatConverts lead under a profile with type, contact info, and attribution data.
leads.create
Create a new lead in WhatConverts under the specified profile. profileId and leadType are required.
Signature
fastify.xwhatconverts.leads.create(params: {
profileId: string;
leadType: "phone_call" | "form" | "chat" | "transaction";
sendNotification?: boolean;
dateTime?: string;
quotable?: boolean;
quoteValue?: number;
salesValue?: number;
leadSource?: string;
leadMedium?: string;
leadCampaign?: string;
leadContent?: string;
leadKeyword?: string;
contactName?: string;
contactEmail?: string;
contactPhone?: string;
leadUrl?: string;
additionalFields?: Record<string, unknown>;
}): Promise<object>
Params
| Name | Type | Required | Description |
|---|---|---|---|
profileId | string | Yes | WhatConverts profile ID to create the lead under. |
leadType | string | Yes | Lead type: phone_call, form, chat, or transaction. |
sendNotification | boolean | No | Send notification email on creation. |
dateTime | string | No | Lead date/time in YYYY-MM-DD HH:MM:SS format. |
quotable | boolean | No | Whether the lead is quotable. |
quoteValue | number | No | Quote value for the lead. |
salesValue | number | No | Sales value for the lead. |
leadSource | string | No | Traffic source (e.g. "google"). |
leadMedium | string | No | Traffic medium (e.g. "cpc"). |
leadCampaign | string | No | Campaign name. |
leadContent | string | No | Ad content identifier. |
leadKeyword | string | No | Search keyword. |
contactName | string | No | Contact's full name. |
contactEmail | string | No | Contact's email address. |
contactPhone | string | No | Contact's phone number. |
leadUrl | string | No | Page URL where the lead originated. |
additionalFields | object | No | Custom key-value fields. |
Returns
The created WhatConverts lead object.
Throws
[xWhatConverts] leads.create: params object is required— called without a params object.[xWhatConverts] leads.create: profileId is required— missingprofileId.[xWhatConverts] leads.create: leadType is required— missingleadType.[xWhatConverts] Network error: <message>— network-level failure.[xWhatConverts] API error: <status>— non-2xx response from WhatConverts.
Examples
Basic — create a form lead
const lead = await fastify.xwhatconverts.leads.create({
profileId: "98765",
leadType: "form",
contactName: "Jane Smith",
contactEmail: "jane@example.com",
leadSource: "google",
leadMedium: "cpc",
});
console.log(lead.lead_id); // created lead ID
Realistic — capture a contact form submission with attribution
fastify.post("/contact", async (request, reply) => {
const { name, email, phone, message } = request.body;
const { utm_source, utm_medium, utm_campaign } = request.query;
const lead = await fastify.xwhatconverts.leads.create({
profileId: process.env.WC_PROFILE_ID,
leadType: "form",
contactName: name,
contactEmail: email,
contactPhone: phone,
leadSource: utm_source,
leadMedium: utm_medium,
leadCampaign: utm_campaign,
leadUrl: request.headers.referer,
sendNotification: true,
additionalFields: { message },
});
return { leadId: lead.lead_id };
});
See Also
- leads.list — list existing leads
- leads.update — update a created lead
- profiles.get — look up the
profileId
AI Context
package: "@xenterprises/fastify-xwhatconverts"
method: fastify.xwhatconverts.leads.create(params)
use-when: Create a new WhatConverts lead programmatically (e.g. form submission, offline conversion import)
params: profileId (string, required), leadType (string, required), plus optional contact/attribution fields
returns: created WhatConverts lead object
