Push leads from your website into Skeduler
developers-push-leadsOn this page
Send a web form to your own server, then create the contact and a job through the API.
Your website's form posts to your own server, and your server calls the API. Never call the API from the browser: that would put your client secret in the page. See Keep your client secret safe.
Who can do this: Owners and Admins with the Manage Developer Tools permission.
Your app needs read:contacts, write:contacts and write:jobs. In the examples, $SKEDULER_API is your Skeduler API address. Contact Skeduler support if you don't have it. In the JavaScript and PHP tabs, the same names in capitals (SKEDULER_API, ACCESS_TOKEN and so on) are variables you set.
For a no-code route, see Turn web form leads into contacts and jobs.
On each submission
-
Look for an existing contact by email, so you don't create a duplicate:
curl
curl -s "$SKEDULER_API/api/v1/contacts?email=$EMAIL" -H "Authorization: Bearer $ACCESS_TOKEN"JavaScript (fetch)
const res = await fetch(`${SKEDULER_API}/api/v1/contacts?email=${EMAIL}`, { headers: { Authorization: `Bearer ${ACCESS_TOKEN}`, }, }); const data = await res.json();PHP (Guzzle)
$client = new \GuzzleHttp\Client(); $res = $client->request('GET', "$SKEDULER_API/api/v1/contacts?email=$EMAIL", [ 'headers' => [ 'Authorization' => "Bearer $ACCESS_TOKEN", ], ]); $data = json_decode((string) $res->getBody(), true); -
Create one if there's none, with an
Idempotency-Keybuilt from the form submission's own id:curl
curl -s -X POST "$SKEDULER_API/api/v1/contacts" \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Idempotency-Key: lead-$SUBMISSION_ID-contact" -H "Content-Type: application/json" \ -d '{"first_name":"Sam","last_name":"Rivera","email":"sam@example.com","mobile_phone":"0400 000 000"}'JavaScript (fetch)
const res = await fetch(`${SKEDULER_API}/api/v1/contacts`, { method: "POST", headers: { Authorization: `Bearer ${ACCESS_TOKEN}`, "Idempotency-Key": `lead-${SUBMISSION_ID}-contact`, "Content-Type": "application/json", }, body: JSON.stringify({"first_name": "Sam", "last_name": "Rivera", "email": "sam@example.com", "mobile_phone": "0400 000 000"}), }); const data = await res.json();PHP (Guzzle)
$client = new \GuzzleHttp\Client(); $res = $client->request('POST', "$SKEDULER_API/api/v1/contacts", [ 'headers' => [ 'Authorization' => "Bearer $ACCESS_TOKEN", 'Idempotency-Key' => "lead-$SUBMISSION_ID-contact", ], 'json' => ['first_name' => 'Sam', 'last_name' => 'Rivera', 'email' => 'sam@example.com', 'mobile_phone' => '0400 000 000'], ]); $data = json_decode((string) $res->getBody(), true); -
Create the job, with the form's message as the description:
curl
curl -s -X POST "$SKEDULER_API/api/v1/jobs" \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Idempotency-Key: lead-$SUBMISSION_ID-job" -H "Content-Type: application/json" \ -d '{"title":"Website enquiry","description":"<what they wrote>","customer_id":"<contact id>"}'JavaScript (fetch)
const res = await fetch(`${SKEDULER_API}/api/v1/jobs`, { method: "POST", headers: { Authorization: `Bearer ${ACCESS_TOKEN}`, "Idempotency-Key": `lead-${SUBMISSION_ID}-job`, "Content-Type": "application/json", }, body: JSON.stringify({"title": "Website enquiry", "description": "<what they wrote>", "customer_id": "<contact id>"}), }); const data = await res.json();PHP (Guzzle)
$client = new \GuzzleHttp\Client(); $res = $client->request('POST', "$SKEDULER_API/api/v1/jobs", [ 'headers' => [ 'Authorization' => "Bearer $ACCESS_TOKEN", 'Idempotency-Key' => "lead-$SUBMISSION_ID-job", ], 'json' => ['title' => 'Website enquiry', 'description' => '<what they wrote>', 'customer_id' => '<contact id>'], ]); $data = json_decode((string) $res->getBody(), true);
To record where the lead came from, pass a lead_source_id taken from GET /job-lookups.
Why the keys matter
If a visitor double-clicks, or your server retries after a timeout, the same key returns the first answer instead of creating a second contact or job. Keep the same key for the same submission, and the answers are stored for 24 hours. See Safe retries.
Related
In this section
- Change a job's status
- Create a job and book a visit from your own system
- Read a job's notes
- Read technicians' leave and time blocks
- Record a payment on an invoice
- API reference
- Authentication API
- Contacts API
- Credit Notes API
- Customers API
- Estimates API
- Invoices API
- Jobs API
- Payments API
- Schedule blocks API
- Technicians API
- Visits API
- Webhooks API
- Customers or contacts, which endpoint do I use?