14.09 Tool | Attio | Create or Update Lead Record

This Python script is a Tool in Relevance AI and is designed for use by the FA | Attio Agent. The script integrates with the Attio API to manage and update lead records associated with people in a database. It performs the following tasks:

  1. Search for a Person by Email or Name:

    • The script first tries to find an existing person in Attio by querying their email address.

    • If no match is found by email, it falls back to searching by the person's full name.

  2. Check for Existing Leads:

    • Once the person is identified, the script checks whether there is an existing lead for the person in a specific pipeline (e.g., "Recruiter" pipeline).

  3. Create or Update Leads:

    • If a lead exists, it updates the lead using a PATCH request, modifying fields such as the lead's name, status, and pipeline.

    • If no existing lead is found, the script creates a new lead with the provided information using a POST request.

  4. Data Preparation:

    • The script builds a payload for the lead that includes key attributes such as the person's name, pipeline, and status.

    • It ensures that no empty fields are included in the payload.

  5. Response Handling:

    • After the lead is created or updated, the script prints the result and provides a URL to view the lead in Attio.

    • In case of an error, the script captures and prints an error message.

This code automates the process of checking, creating, and updating leads in Attio, simplifying lead management and ensuring that existing records are updated efficiently.

Key Components:

  • Attio API Token: Used to authenticate requests.

  • Search Functions: Look up people by email or name.

  • Lead Management: Checks for existing leads and either updates or creates new ones.

  • PATCH/POST Requests: Sends updates (PATCH) or creates new records (POST) via Attio's API.

This script is useful for managing leads in systems where leads need to be continuously tracked and updated based on new data.

Last updated