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:
-
Is there an API endpoint available to upload an attachment to a bill in FreeAgent?
-
If yes, could you please share the correct API URL and payload format?
-
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
}