How to send attachment using bill api

I am currently facing an issue while working with the FreeAgent API. I am able to create a bill successfully using the Bill API, but I am stuck on how to upload an attachment to the same bill.

I checked the API documentation, but I couldn’t find any API endpoint that allows uploading or attaching a file to a bill. I only found details about creating bills, but nothing related to inserting attachments.

API refernce: FreeAgent Developer Dashboard

Could you please guide me on:

  1. Is there an API endpoint available to upload an attachment to a bill in FreeAgent?

  2. If yes, could you please share the correct API URL and payload format?

  3. If no, is there any alternative method to associate documents with a bill programmatically?

Below is my code:

function freeagent_old_createBill($data, $id, $is_line_items = 0)
   {

    $access_token = 'xxxxxxxxxxxxxxxxxxxx';



    /\* STEP 1: CREATE BILL \*/

    $billPayload = \[

        "bill" => \[

            "contact"      => "https://api.sandbox.freeagent.com/v2/contacts/211536",

            "reference"    => "BILL-10012",

            "dated_on"     => "2025-01-10",

            "due_on"       => "2025-01-20",

            "bill_items" => \[

                \[

                    "category"       => "https://api.sandbox.freeagent.com/v2/categories/285",

                    "description"    => "Office supplies purchase",

                    "sales_tax_rate" => "20.0",

                    "total_value"    => "500.00"

                \]

            \]

        \]

    \];



    $ch = curl_init("https://api.sandbox.freeagent.com/v2/bills");

    curl_setopt_array($ch, \[

        CURLOPT_POST           => true,

        CURLOPT_RETURNTRANSFER => true,

        CURLOPT_HTTPHEADER     => \[

            "Authorization: Bearer $access_token",

            "Content-Type: application/json",

            "User-Agent: MyApp (support@myapp.com)"

        \],

        CURLOPT_POSTFIELDS => json_encode($billPayload)

    \]);



    $response = curl_exec($ch);

    curl_close($ch);



    $billResponse = json_decode($response, true);



    if (!isset($billResponse\['bill'\]\['url'\])) {

        return \[

            "error" => "Failed to create bill",

            "response" => $response

        \];

    }

    $bill_url = $billResponse\['bill'\]\['url'\];   // full URL

 }

To attach a file to a FreeAgent bill, you must include the attachment data directly within the bill payload when you create or update the bill using the standard bill API endpoint (/v2/bills). There is no separate upload endpoint. The file must be Base64 encoded and included in the attachment object of your JSON request, specifying the file_name, content_type, and the Base64 data string.

Best regards,
John Finch

Thank you @johnfinch204.

I will try.