# Developer Guidelines

# Getting started

Our API for Easy PV and Heatpunk is open, and we welcome developers working on new integrations for CRMs, job management platforms and other applications. If you have an application that you would like to connect please give us a shout - we'd be really happy to help.

#### Documentation and testing

Live documentation for the API can be found at [https://heatpunk.co.uk/api/about/](https://heatpunk.co.uk/api/about/). You can alternatively view the full OpenAPI schema by navigating to `[DOMAIN]/api/openapi/`

You can test calls from the documentation itself. It will also give example CURL calls which you can test from a command line. Platforms such as [Postman](https://www.postman.com/) or [Hoppscotch](https://hoppscotch.io/) are also very useful for development of an API integration.

#### Production and sandbox environments

In all the examples we give here we use the production API at the [https://heatpunk.co.uk/](https://heatpunk.co.uk/) domain. If you are developing an integration with another application where you feel it would be helpful to test on a pre-prod environment we can give you access to a sandbox environment. Please ask for details.

#### Generating an API key

Most API endpoints that we make publicly available can only be accessed through a 'pro' team API key or an Enterprise API key. For 'Pro' team owners and admins please login and go to your 'Pro account settings' dashboard, then click on the 'CRM connections' tab. Click on the 'Generate key' button to create an API key.

It is very important that you keep the API key secure. Anyone who gains access to it will be able to access and change all data for the users in your team, including customer names and addresses. We recommend it is only used for server-server requests, and stored as an environment variable and kept out of git repositories. If you wish to keep a backup of the key, use a secure password manager.

Note that we don't keep a record of the key. If you lose it, you will need to generate a new one for your application.

If you are developing an application just for one company, you will only need to generate one key. If you have a platform that many companies use, every company will need to generate their own key and save it to their account on your platform.

# API endpoints



# Projects: Create, list & update

This guide walks you through creating, updating and archiving projects using our Open API.

Jump to section:

- [POST /projects/create](https://help.heatpunk.co.uk/link/100#bkmrk-post-%2Fprojects%2Fcreat-1)
- [POST /projects/list](https://help.heatpunk.co.uk/link/100#bkmrk-patch-%2Fprojects%2Fupda)
- [PATCH /projects/update](https://help.heatpunk.co.uk/link/100#bkmrk-patch-%2Fprojects%2Fupda-1)

---

## `POST` /projects/create

Use this endpoint to create new projects.

<details id="bkmrk-authentication-endpo"><summary>Authentication</summary>

**Endpoint:**

```javascript
POST https://[DOMAIN]/api/v1/projects/create
```

**Headers:**

- `accept: application/json`
- `X-API-KEY: YOUR_API_KEY` (Replace `YOUR_API_KEY` with your actual API key.)
- `Content-Type: application/json`

</details><details id="bkmrk-request-structure-ev"><summary>Request structure</summary>

Every request to create a new project must include a JSON object with the following:

**Owner field:** The `owner` should be a valid email address of an Easy PV Pro team member. This email will become the primary project owner.

**Meta object:** Use the `meta` object to pass in parameters for the project. All fields are optional.

- **`buildDate`** Sets the design mode for the project. Allowed values: 
    - `"pre2000"`
    - `"post2000"`
    - `"post2006"`
- `projectName`
- `customerName`
- `customerEmail`
- `customerPhone`
- `address`
- `postcode`
- `lat` and `lng` - provide the latitude and longitude in the [decimal degrees](https://en.wikipedia.org/wiki/Decimal_degrees) format
- `status` - set the status of the project. Allowed values: 
    - `"Lead"`
    - `"Quote"`
    - `"Sale"`
    - `"Install"`
    - `"Completed"`
    - `"Rejected"`
- `crmReference` - include an ID or reference to the customer record or project in your CRM

</details><details id="bkmrk-example-api-request-"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to create a project with the required fields:

```json
curl -X POST 'https://heatpunk.co.uk/api/v1/projects/create' \
     -H 'accept: application/json' \
     -H 'X-API-KEY: YOUR_API_KEY' \
     -H 'Content-Type: application/json' \
     -d '{
           "owner": "sales@example.com",
           "meta": {
               "customerName": "Joe Bloggs",
               "address": "123 Sample Street",
               "postcode": "AB12 3CD"
           }
         }'
```

##### Response

A successful call returns a JSON object containing a `projectId` which you should store in your own database for future reference.

You can use the ID to construct a link directly to the project using the following link structure:

```php
https://heatpunk.co.uk/?project=[PROJECT ID]
```

</details>
---

## `POST` /projects/list

Use this endpoint to get a list of projects.

<details id="bkmrk-authentication-endpo-1"><summary>Authentication</summary>

**Endpoint:**

```javascript
POST https://[DOMAIN]/api/v1/projects/list
```

**Headers:**

- `X-API-KEY: [YOUR_API_KEY]` (Replace `[YOUR_API_KEY]` with your actual API key.)

</details><details id="bkmrk-request-structure-ev-1"><summary>Request structure</summary>

Every request to update a project must contain a JSON object with the following.

**User email:** The `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the projects.

**Start date:** `start` should be in the format (YYYY-MM-DD)

**End date:** `end` should be in the format (YYYY-MM-DD)

</details><details id="bkmrk-example-api-request--1"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to retrieve a list of projects:

```json
curl -X POST 'https://heatpunk.co.uk/api/v1/projects/list' \
     -H 'X-API-KEY: YOUR_API_KEY' \
     -d '{
          "ownerEmail": "matt.agnes+proBasic@midsummerenergy.co.uk",
          "start": "2025-05-22",
          "end": "2025-11-22"
      }'
```

##### Response

A successful request returns a `projects` object containing a list of projects within the specified date range. For example:

```json
{
    "status": "success",
    "projects": [
        {
            "ID": 1353680,
            "owner": 27091,
            "dateCreated": "2025-09-01T09:14:30.000Z",
            "dateModified": "2025-12-04T11:52:18.000Z",
            "projectName": "Mon Sep 01 2025",
            "customerName": "",
            "address": "105 Sample Road Cambridge Cambridgeshire",
            "postcode": "CB1 3QD",
            "lat": 52.193912506103516,
            "lng": 0.15014299750328064,
            "status": "Lead"
        },
    ...
    ],
    "ownerEmail": "matt.agnes+proBasic@midsummerenergy.co.uk",
    "ownerID": 00123
}
```


</details>
---


## `PATCH` /projects/update

Use this endpoint to update core project data for an existing project.

<details id="bkmrk-authentication-endpo-2"><summary>Authentication</summary>

**Endpoint:**

```javascript
PATCH https://[DOMAIN]/api/v1/projects/update
```

**Headers:**

- `accept: application/json`
- `X-API-KEY: [YOUR_API_KEY]` (Replace `[YOUR_API_KEY]` with your actual API key.)
- `Content-Type: application/json`

</details><details id="bkmrk-request-structure-ev-2"><summary>Request structure</summary>

Every request to update a project must contain the project id, user email, and new data to be updated. The `data` must be an object with keys for each field to be updated.

**Project ID:** The `projectId` as a number.

**User email:** The `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.

**Data object:** Include a `data` object that will contain the information to be updated. We currently support a `meta` object with keys for each field to be updated. See the projects/create and projects/data endpoint documentation for the list of project meta fields that can be updated.

</details><details id="bkmrk-example-api-request--2"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to update a project:

```json
curl -X PATCH 'https://heatpunk.co.uk/api/v1/projects/update' \
     -H 'accept: application/json' \
     -H 'X-API-KEY: YOUR_API_KEY' \
     -H 'Content-Type: application/json' \
     -d '{
        "projectId": 986206,
        "userEmail": "matt.agnes+pro@midsummerenergy.co.uk",
        "data": {
            "meta": { "status": "Completed"}
                }
        }'
```

##### Response

If the request is successful you will receive a 204 success response.

</details>
---



<p class="callout warning">We have updated the attribute used by the API when specifying the email address of the user that owns the record so it is consistent across all our endpoints. We now always refer to this attribute as `userEmail`. If you previously used `ownerEmail` this will still work as it has been set up as an alias of `userEmail`.</p>

# Projects: Forms & files

Within Easy PV and Heatpunk, users complete forms and generate PDF reports. In your application you may want to view the completed files and forms associated with a project, and fetch completed form data and PDF documents.

Jump to section:

- [GET /forms/list](https://help.heatpunk.co.uk/link/101#bkmrk-post-%2Fprojects%2Fcreat-1)
- [GET /forms/form](https://help.heatpunk.co.uk/link/101#bkmrk-get-%2Fforms%2Fform)
- [GET /files/list](https://help.heatpunk.co.uk/link/101#bkmrk-get-%2Ffiles%2Flist-1)
- [GET /files/file](https://help.heatpunk.co.uk/link/101#bkmrk-get-%2Ffiles%2Ffile-1)

---

### `GET` /forms/list

Use this endpoint to get a list of completed forms for a project.

<details id="bkmrk-authentication-endpo"><summary>Authentication</summary>

**Endpoint:**

```javascript
GET https://[DOMAIN]/api/v1/projects/forms/list
```

**Headers:**

- `X-API-KEY: YOUR_API_KEY` (Replace `YOUR_API_KEY` with your actual API key.)

</details><details id="bkmrk-request-structure-ev"><summary>Request structure</summary>

Every request must contain the project ID and user email as GET parameters.

**Project ID:** The `projectId` as a number.

**User email:** The `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.

`userEmail` is necessary as the API key is shared amongst all members of your team, but projects aren't necessarily shared with all members of the team. When we receive the request we will check if the given email has the right to access the project.

</details><details id="bkmrk-example-api-request-"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to create a project with the required fields:

```javascript
curl  -X GET 'https://heatpunk.co.uk/api/v1/projects/forms/list?projectId=12345&userEmail=sales%2540midsummerenergy.co.uk' \
      -H 'X-API-KEY: ---KEY---'

```

##### Response

A successful call returns a JSON object containing a `forms` and `surveys` object, which contains the completed forms and surveys.

```json
{
  "forms": [
    {
      "id": "proposal"
    },
    {
      "id": "enaConnect"
    }
  ],
  "surveys": []
}

```

</details>
---


### `GET` /forms/form

Use this endpoint to retrieve form fields.

<details id="bkmrk-authentication-endpo-1"><summary>Authentication</summary>

**Endpoint:**

```javascript
GET https://[DOMAIN]/api/v1/projects/forms/form
```

**Headers:**

- `X-API-KEY: YOUR_API_KEY` (Replace `YOUR_API_KEY` with your actual API key.)

</details><details id="bkmrk-request-structure-re"><summary>Request structure</summary>

Request must contain the project ID and user email as GET parameters. You will also need to include the ID of the form.

Form category also must be set if you are requesting survey forms.

**Project ID:** The `projectId` as a number.

**User email:** The `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.

**Form:** The ID of the `form` (from the response above).

**Form Category:** The `formCategory` currently only needs to be set if requesting survey forms.

Allowed Values:

- - `"forms"`
    - `"surveys"`

</details><details id="bkmrk-example-api-request--1"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to create a project with the required fields:

```javascript
curl -X GET 'https://heatpunk.co.uk/api/v1/projects/forms/form?projectId=12345&userEmail=sales%2540midsummerenergy.co.uk&form=letterOfConsent' \
     -H 'X-API-KEY: ---KEY---'

```

##### Response

A successful call returns a JSON object containing a `form` object, which contains the fields in the form.

```json
{
  "form": {
    "details": {
      "coverLetterHeading": "...",
      "coverLetter": "..."
    },
    "quote": {
      "quoteReference": "32836",
      "validFor": "30 days"
    },
    "scope": {
      "show": "No",
      "scopeOfWorks": ""
    },
    "terms": {
      "show": "No",
      "terms": ""
    }
  }
}
```

</details>
---



### `GET` /files/list

Use this endpoint to get a list of files saved to a project.

<details id="bkmrk-authentication-endpo-2"><summary>Authentication</summary>

**Endpoint:**

```javascript
GET https://[DOMAIN]/api/v1/files/list
```

**Headers:**

- `X-API-KEY: YOUR_API_KEY` (Replace `YOUR_API_KEY` with your actual API key.)

</details><details id="bkmrk-request-structure-re-1"><summary>Request structure</summary>

Request must contain the project ID, and user email as GET parameters. You must also set the type of the return object.

**ID:** The `id` of the project as a number.

**User email:** The `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.

**Type:** Set the `type` property to `"projects"`

</details><details id="bkmrk-example-api-request--2"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to create a project with the required fields:

```javascript
curl -X GET 'https://heatpunk.co.uk/api/v1/files/list?id=872034&userEmail=sales%40midsummerenergy.co.uk&type=projects' \
     -H 'X-API-KEY: ---KEY---'

```

##### Response

A successful call returns a JSON object containing a `fileRegistry` object. Files saved within the project will be contained in the `uploads` array of the response.

```json
{
  "fileRegistry": {
    "uploads": {
      "heatPumpCommissioningChecklist": [
        {
          "name": "Fri Dec 27 2024 -hp-commissioning~Heat Pump Commissioning Checklist.pdf",
          "size": 83175,
          "created": "1970-01-01T00:00:00.000Z",
          "modified": "2026-01-13T17:01:29.107Z",
          "format": ".pdf"
        }
      ]
    }
  }
}
```

</details>
---



### `GET` /files/file

Use this endpoint to download a file.

<details id="bkmrk-authentication-endpo-3"><summary>Authentication</summary>

**Endpoint:**

```javascript
GET https://[DOMAIN]/api/v1/files/file
```

**Headers:**

- `X-API-KEY: YOUR_API_KEY` (Replace `YOUR_API_KEY` with your actual API key.)

</details><details id="bkmrk-request-structure-re-2"><summary>Request structure</summary>

Request must contain the project ID, and user email as GET parameters. You must also set the type of the return object, file category and the name of the file.

**ID:** The `id` of the project as a number.

**User email:** The `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.

**Type:** Set the `type` property to `"projects"`

**File category:** Set `fileCategory` to `"uploads"`

**File:** The name of the `file` (from the response above).

(Optional) **Response format:** You can specify the `responseFormat` from the allowed values:

- `"raw"` file as stored (Default).
- `"b64"` JSON object with image in base64 format and metadata.
- `"meta"` Just metadata.

</details><details id="bkmrk-example-api-request--3"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to create a project with the required fields:

```javascript
curl -X GET 'https://heatpunk.co.uk/api/v1/files/file?type=projects&id=872034&userEmail=andy%2Bjumptech%40midsummerenergy.co.uk&fileCategory=uploads&file=test%20project%20%20letter%20of%20consent~Letter%20of%20Consent.pdf&responseFormat=b64' \
     -H 'X-API-KEY: ---KEY---'
```

##### Response

If the request is successful you will receive a 200 success response and returns the specified file.

</details>

# Projects: Get project data

Easy PV and Heatpunk generate a full bill of materials for a project, and for our UK and Ireland sites you can very quickly place an order for the components from Midsummer. So you may like to import the shopping cart into your application and display an ordering link. Users love the ease of ordering all the kit for an installation.

The cart is based on the bill of materials generated by the software for a given project. The bill of materials for the project is refreshed every time the overview page of the project is opened by a user in Easy PV or Heatpunk.

---

#### `GET` /projects/data

Use this endpoint to fetch project data.

<details id="bkmrk-authentication-endpo"><summary>Authentication</summary>

**Endpoint:**

```javascript
GET https://[DOMAIN]/api/v1/projects/data
```

**Headers:**

- `X-API-KEY: YOUR_API_KEY` (Replace `YOUR_API_KEY` with your actual API key.)

</details><details id="bkmrk-request-structure-ev"><summary>Request structure</summary>

Every request to create a new project must include the following:

**ID:** The `id` of the project as a number.

**User email:** The `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.

</details><details id="bkmrk-example-api-request-"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to create a project with the required fields:

```javascript
curl -X GET 'https://heatpunk.co.uk/api/v1/projects/data?projectId=96206&userEmail=matt.agnes%2Bpro%40midsummerenergy.co.uk' \
     -H 'accept: application/json' \
     -H 'X-API-KEY: YOUR_API_KEY'
```

##### Response

A successful call returns a `projectData` object which will include core project data plus `cart` and `midsummerOrderLink` arrays.

The `projectData` object will include core project and customer information. For example:

```json
"projectData": {
    "lat": 52.933899128353076,
    "lng": -1.22907350946869,
    "zoom": 19,
    "address": "1",
    "postcode": "NG93DY",
    "dateCreated": "2025-12-17 09:26:11",
    "dateModified": "2026-01-14 17:15:42",
    "projectName": "Sample Project",
    "customerName": "Test Testington",
    "buildDate": "pre2000",
    "customerPhone": "0123456789",
    "customerEmail": "email@example.com",
    "projectType": "heat",
    "userID": "10828",
    "projectID": "53792",
    "altitude": 67.37315368652344,
    "geography": {
      "altitude": null,
      "distance": null,
      "hillSlope": null,
      "hillZone": null,
      "terrain": null,
      "topography": null,
      "windZone": null
    }
```

The `cart` array contains the full bill of materials as a JSON object. This contains details of all the products that have been specified in the project. For example:

```json
"cart": [
      {
        "name": "Mitsubishi Ecodan 14kW",
        "qty": 1,
        "item": 7155.55,
        "line": 7155.55,
        "dbID": "4058#4734",
        "availableFrom": {
          "midsummer": {
            "ID": "4058#4734",
            "price": 7155.55
          }
        }
      },
      {
        "name": "UK Cylinders 300L FlowCyl Standard Cylinder",
        "qty": 1,
        "item": 1349.78,
        "line": 1349.78,
        "dbID": "4666",
        "availableFrom": {
          "midsummer": {
            "ID": "4666",
            "price": 1349.78
          }
        }
      }
    ]
```

The `midsummerOrderLink` is a URL that can be used to order everything needed for a project from Midsummer. For example:

```json
"midsummerOrderLink": "https://midsummerwholesale.co.uk/upload/?order=eyJpdGVtcyI6eyI3OCI6eyJ0aXRsZSI6IkxhYmVsIHNoZWV0IiwicXR5IjoyfSwiMzgwIjp7InRpdGxlIjoiMTAwbSByZWVsIG9mIDZtbTIgc29sYXIgY2FibGUiLCJxdHkiOjF9LCIxNzc5Ijp7InRpdGxlIjoiTUM0IDZtbSBDb25uZWN0b3IgUGFpciIsInF0eSI6NH0sIjIyOTgiOnsidGl0bGUiOiJUaWdvIFJldHJvZml0IEZyYW1lIE1vdW50ZWQgT3B0aW1pc2VyIFRTNC1BLU8iLCJxdHkiOjZ9LCIyNTg2Ijp7InRpdGxlIjoiRmFzdGVuc29sIHJhaWwgc3BsaWNlIiwicXR5Ijo2fSwiMjU4NyI6eyJ0aXRsZSI6IkZhc3RlbnNvbCByYWlsIGJvbHQiLCJxdHkiOjZ9LCIyNTk0Ijp7InRpdGxlIjoiRmFzdGVuc29sIHBvcnRyYWl0IGZsYXQgdGlsZSByb29mIGhvb2siLCJxdHkiOjI0fSwiMjgxMiI6eyJ0aXRsZSI6IkJhdHRlcnkgSGF6YXJkIFdhcm5pbmcgTGFiZWwgUGFjayIsInF0eSI6MX0sIjI4MTQiOnsidGl0bGUiOiIqKk5FVCoqIEVtbGl0ZSBCaS1kaXJlY3Rpb25hbCBNZXRlciBFQ0EyLm4qIiwicXR5IjoxfSwiMzA0MCI6eyJ0aXRsZSI6Ikdpdi5BQyAzLjAgaW52ZXJ0ZXIiLCJxdHkiOjF9LCIzMDQ2Ijp7InRpdGxlIjoiR2l2RW5lcmd5IFdpRmkgRG9uZ2xlIiwicXR5IjoxfSwiMzE1NyI6eyJ0aXRsZSI6IkZhc3RlbnNvbCBibGFjayB1bml2ZXJzYWwgY2xhbXAiLCJxdHkiOjE4fSwiMzU4NCI6eyJ0aXRsZSI6Ikdyb3dhdHQgU2hpbmVXaUZpLVgiLCJxdHkiOjF9LCIzNjU1Ijp7InRpdGxlIjoiR2l2RW5lcmd5IERDIE1pbmlhdHVyZSBDaXJjdWl0IEJyZWFrZXIgKE1DQikiLCJxdHkiOjJ9LCI0Mjg0Ijp7InRpdGxlIjoiR2l2RW5lcmd5IDUuMmtXaCBMaUZlUE80IEJhdHRlcnkiLCJxdHkiOjF9LCI0NDg0Ijp7InRpdGxlIjoiR2l2RW5lcmd5IFBsdWcgdG8gTHVnIENhYmxlIChHZW4zKSIsInF0eSI6MX0sIjQ0OTMiOnsidGl0bGUiOiJBQyBpc29sYXRvciAtIElNTyAtIDIwQSA0LXBvbGUiLCJxdHkiOjJ9LCI0NTU1Ijp7InRpdGxlIjoiQUMgaXNvbGF0b3IgLSBJTU8gLSA2M0EgNC1wb2xlIiwicXR5IjoyfSwiNTEwNSI6eyJ0aXRsZSI6IlJ1YmJlciBHcm9tbWV0IGZvciBHZW4zIEludmVydGVyIFBsdWcgQ2FibGVzIiwicXR5IjoxfSwiNTI2NSI6eyJ0aXRsZSI6IkppbmtvIFRpZ2VyIE5lbyA0NDBXIE4tVHlwZSBBbGwgQmxhY2sgTW9ubyBzb2xhciBwYW5lbCIsInF0eSI6Nn0sIjUyNzYiOnsidGl0bGUiOiJGYXN0ZW5zb2wgc2lsdmVyIHJhaWwgMzU1MG1tIiwicXR5Ijo3fSwiNTM5NyI6eyJ0aXRsZSI6Ikdyb3dhdHQgTUlOIDEwMDAwIFRMLVgyIFRocmVlIE1QUFQgMXBoIGludmVydGVyIiwicXR5IjoxfSwiNTU2MSI6eyJ0aXRsZSI6IkdpdkVuZXJneSBHRU0xMjBDVCBNb2RidXMgRW5lcmd5IE1ldGVyIiwicXR5IjoxfSwiIjp7InRpdGxlIjoiTWF0dCBTY2FmZm9sZGluZyBvdmVyIGNvbnNlcnZhdG9yeSIsInF0eSI6MX0sIjI2NDgjMzU5MCI6eyJ0aXRsZSI6IkZhc3RlbnNvbCBibGFjayBlbmQgY2FwIiwicXR5IjoxMn19LCJ0cmFjZSI6eyJzcmMiOiJlYXN5LXB2IiwibW9kZSI6InVrIiwicHJvamVjdElEIjoiOTg2MjA2In19",
```


</details>---

#### **Customise cart and order links**

If you wish to modify the bill of materials for a project and create your own `cart` object, you can use this to generate a custom order link. If you do this, you can also add some additional parameters such as a delivery address or order reference to the order (see instructions in the next section).

In its simplest form, an order can be just an object with an 'items' property. For each item, specify the the products by providing the product ID and the quantity required.

```json
const order = {
    "items": {
        "2586": {
            "qty": 99
        },
       "4258": {
            "qty": 99
       }
   }
}
```

Here is a more complex order, with a shipping address, despatch date and reference:

```json
const order = {
    "items": {
        "2586": {
            "qty": 99
        },
   },
  "deliveryOption": "standard",
  "shippingAddress": {
    "postcode": "CB24 6AZ",
    "add1": "Midsummer Energy",
    "add2": "Cambridge Road Industrial Estate",
    "add3": "Milton",
    "add4": "",
    "email": "sales@midsummerenergy.co.uk",
    "phone": "01223 858414",
    "firstname": "Andy",
    "lastname": "Rankin"
  },
  "despatchDate": "2023-02-08",
  "reference": "trial order"
}
```

Once you have created the JSON object containing the products required for the project you can create an order string by following these steps:

1. Stringify the object
2. Base64 encode the result of the stringified object
3. URL encode the base64 encoded string
4. Append your string to the following URL to create your custom order link `https://midsummerwholesale.co.uk/upload?order=[result string]`

In JavaScript the function you need to generate an order is:

```javascript
 function createOrderLink(order) {
      return "https://midsummerwholesale.co.uk/upload?order="+encodeURIComponent(btoa(JSON.stringify(order)))
  }
```

# Leads: Fetch, create, update & delete

This guide covers the API endpoints that handle leads.

Jump to section:

- [POST /leads/fetch](https://help.heatpunk.co.uk/link/252#bkmrk-patch-%2Fprojects%2Fupda)
- [POST /leads/create](https://help.heatpunk.co.uk/link/252#bkmrk-patch-%2Fprojects%2Fupda-1)
- [POST /leads/update](https://help.heatpunk.co.uk/link/252#bkmrk-post-%2Fleads%2Fupdate)
- [DELETE /leads/delete](https://help.heatpunk.co.uk/link/252#bkmrk-delete-%2Fleads%2Fdelete)

---

##  `POST` /leads/fetch

Use this endpoint to get all the leads from your leads dashboard so you can see them in your CRM.

<details id="bkmrk-authentication-endpo-1"><summary>Authentication</summary>

**Endpoint:**

```javascript
POST https://[DOMAIN]/api/v1/leads/fetch
```

**Headers:**

- `X-API-KEY: [YOUR_API_KEY]` (Replace `[YOUR_API_KEY]` with your actual API key.)

</details><details id="bkmrk-request-structure-yo"><summary>Request structure</summary>

Every request must include `userEmail` and `furthestDate` in the body.

**User email:** `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.

**Furthest date:** `furthestDate` should be in the format (YYYY-MM-DD).

</details><details id="bkmrk-example-api-request-"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to fetch leads:

```javascript
curl  -X POST 'https://heatpunk.co.uk/api/v1/leads/fetch' \
      -H 'x-api-key: YOUR_API_KEY_HERE'
      -d '{
            "userEmail": "saira.noor@midsummerenergy.co.uk",
            "furthestDate": "2025-09-10"
          }'
```

##### Response

A successful call will return a JSON array of lead objects, that looks like this:

```javascript
{
    "rows": {
        "32123": {
        "dateCreated": "2025-03-11T11:03:29.000Z",
        "status": "new",
        "customerName": "John Doe",
        "address": "8 The Rowans, Milton, Cambridge, Cambridgeshire, CB24 6YU",
        "customerEmail": "test@test.com",
        "customerPhone": "07111111111",
        ...
        },
    ...
    }
}
```


</details>
---


## `POST` /leads/create

Use this endpoint to insert a lead that comes from sources that aren't Speedy PV.

<details id="bkmrk-authentication-endpo"><summary>Authentication</summary>

**Endpoint:**

```javascript
POST https://[DOMAIN]/api/v1/leads/create
```

**Headers:**

- `X-API-KEY: [YOUR_API_KEY]` (Replace `[YOUR_API_KEY]` with your actual API key.)

</details><details id="bkmrk-request-structure-ev-1"><summary>Request structure</summary>

The request body can take the following parameters:

- `address` can include the postcode.
- `postcode`
- `customerEmail`
- `customerName`
- `customerPhone`
- `lat` and `lng` in [decimal degrees ](https://en.wikipedia.org/wiki/Decimal_degrees)format.

</details><details id="bkmrk-example-api-request--1"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to save a lead with the require fields:

```javascript
curl  -X POST 'https://heatpunk.co.uk/api/v1/leads/create' \
      -H 'x-api-key: YOUR_API_KEY_HERE' \
      -d '{
            "address": "7 Erdiston Ct, Bude, EX23 8HE",
            "customerName": "John Doe",
            "customerEmail": "john.doe@example.com",
            "customerPhone": "1234567890"
          }'
```

##### Response

A successful call will return a JSON object containing a `leadId`.


</details>
---


## `POST` /leads/update

Use this endpoint to update the details of a lead.

<details id="bkmrk-authentication-endpo-2"><summary>Authentication</summary>

**Endpoint:**

```javascript
POST https://[DOMAIN]/api/v1/leads/update
```

**Headers:**

- `X-API-KEY: [YOUR_API_KEY]` (Replace `[YOUR_API_KEY]` with your actual API key.)

</details><details id="bkmrk-request-structure-ev"><summary>Request structure</summary>

Every request must include the following in the request body:

- **Lead ID:** The `leadID` of the lead you want to update.
- **User email:** `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.
- **Fields object:** A `fields` object containing the information to be updated. See the projects/create endpoint documentation for the list of meta fields that can be updated.

</details><details id="bkmrk-example-api-request--2"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to save a lead with the required fields:

```javascript
curl  -X POST 'https://heatpunk.co.uk/api/v1/leads/update' \
      -H 'x-api-key: YOUR_API_KEY_HERE' \
      -d '{
            "leadID": "1001",
            "userEmail": "saira.noor@midsummerenergy.co.uk",
            "fields": {
              "address": "123 main st"
            }
          }'
```

##### Response

If the request is successful you will receive a 204 success response.


</details>
---


## `DELETE` /leads/delete

Use this endpoint to delete leads from your leads dashboard.

<details id="bkmrk-authentication-endpo-3"><summary>Authentication</summary>

**Endpoint:**

```javascript
DELETE https://[DOMAIN]/api/v1/leads/delete
```

**Headers:**

- `X-API-KEY: [YOUR_API_KEY]` (Replace `[YOUR_API_KEY]` with your actual API key.)

</details><details id="bkmrk-request-structure-ev-2"><summary>Request structure</summary>

Every request must include the following in the request body:

- **Lead ID:** The `leadID` of the lead you want to update.
- **User email:** `userEmail` should be a valid email address of an Easy PV Pro team member who has access to the project.

</details><details id="bkmrk-example-api-request--3"><summary>Example API request and response</summary>

##### Example API Request

Below is an example using `curl` that demonstrates how to save a lead with the require fields:

```javascript
curl  -X DELETE 'https://heatpunk.co.uk/api/v1/leads/delete' \
      -H 'x-api-key: YOUR_API_KEY_HERE' \
      -d '{
            "leadID": "1001"
            "userEmail": "saira.noor@midsummerenergy.co.uk"
          }'
```

##### Response

If the request is successful you will receive a 200 success response.


</details>