# How to create Lead via API

🚀 **Create a New Lead Using API**

**Step 1: Generate an API Key**

1. Go to:

Copy

```
{{workspaceUrl}}/workspace-config?tab=api-key
```

1. **Generate and Copy** the API key.

***

**Step 2: Get Company ID**

**📍 Endpoint:**

Copy

```
{{URL}}/accounts/companies
```

**🛠️ Set Headers:**

Copy

```
x-api-key = api Key
```

You'll get a response like this

Copy

```
{
    "message": "Companies accosiated with API token.",
    "companies": [
        {
            "_id": "6525994184e9ddd79853450e",
            "name": "onethread123",
            "logo": "",
            "extraSmallLogo": "",
            "largeLogo": ""
        }
    ]
}
```

**📝 What to Do:**

* Get the **company ID** from the response:

Copy

```
companies[0]._id
```

* **Store the ID** for later:

Copy

```
const companyid = "COMPANY_ID_HERE";  // Replace with actual ID
```

***

**Step 3: Get Client Role ID**

**📍 Endpoint:**

Copy

```
{{URL}}/roles?type=company
```

**🛠️ Set Headers:**

Copy

```
x-api-key = api Key
```

You'll get a response like this

Copy

```
{
    "roles": [
        {
            "_id": "6525994184e9ddd798534535",
            "role": {
                "_id": "6525994184e9ddd79853451e",
                "responsibility": "",
                "name": "client"
            },
            "company": "6525994184e9ddd79853450e",
            "createdAt": "2023-10-10T18:34:41.567Z",
            "updatedAt": "2024-10-01T07:28:48.340Z",
            "__v": 0,
            "type": "company"
        }
    ]
}
```

**📝 What to Do:**

* Find the role with **"client"** name:

Copy

```
roles[0].role.name === "client"
```

* **Store the Client Role ID:**

Copy

```
roles[0]._id
```

**Make sure that you did not copy the \_id of roles\[0].role object**

***

**Step 4: Create a New Lead**

**📍 Endpoint:**

Copy

```
{{URL}}/company/{{companyId}}/members/bulk-client
```

**🛠️ Headers:**

Copy

```
x-api-key: apiKey
companyid: <companyId>
```

**📦 Request Body:**

Copy

```
    "members": [
        {
            "firstName": "John",
            "lastName": "Doe",
            "email": "john.doe@example.com",
            "role": "ROLE_ID_HERE",
            "isConvertedClient": false,
            "status": "New",
            "contactNo": "1234567890",
            "source": "website",
            "positionInBoard": 1,
            "isConvertedClient": false
        }
    ]
}
```

***

**✅ Success Response:**

Copy

```
{
    "message": "Lead created successfully",
    "createdMembers": [
        {
            "_id": "NEW_MEMBER_ID",
            "name": "John Doe",
            "status": "New",
            "role": "client"
        }
    ]
}
```

***

**❗ Important Tips:**

* Make sure `"isConvertedClient": false` is set in the request.
* Use the correct **Role ID** from Step 3.
