# Sent Faxes

## List Sent Faxes

GET `/sent_faxes` — Returns a paginated list of sent faxes for your account.

Query params: `page`, `page_size`, `from_number`, `to_number`, `patient_name`, `patient_dob`, `sender_name`, `recipient_name`, `date_start`, `date_end`, `is_test`, `sort`, `sort_dir`.

#### cURL

```bash
export API_BASE="https://api.medsender.com/api/v2"
export API_KEY="sk_test_..."

curl -s -H "Authorization: Bearer $API_KEY" \
  "$API_BASE/sent_faxes?page=1&page_size=10&date_start=2024-10-01&date_end=2024-10-31" | jq
```

#### Node

```javascript
const API_BASE='https://api.medsender.com/api/v2';
const API_KEY='sk_test_...';
const res=await fetch(`${API_BASE}/sent_faxes?page=1&page_size=10`,{headers:{Authorization:`Bearer ${API_KEY}`}});
console.log(await res.json());
```

#### TypeScript

```typescript
const API_BASE: string = 'https://api.medsender.com/api/v2';
const API_KEY: string = 'sk_test_...';
const res = await fetch(`${API_BASE}/sent_faxes?page=1&page_size=10`, { headers: { Authorization: `Bearer ${API_KEY}` } });
console.log(await res.json());
```

#### Python

```python
import requests
API_BASE='https://api.medsender.com/api/v2'
API_KEY='sk_test_...'
r=requests.get(f"{API_BASE}/sent_faxes", headers={'Authorization':f'Bearer {API_KEY}'}, params={'page':1,'page_size':10})
print(r.json())
```

#### Ruby

```ruby
require 'net/http'
require 'uri'
uri = URI.parse('https://api.medsender.com/api/v2/sent_faxes?page=1&page_size=10')
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer sk_test_...'
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true){|http| http.request(request)}
puts res.body
```

#### PHP

```php
<?php
$ch = curl_init();
curl_setopt_array($ch, [
  CURLOPT_URL => 'https://api.medsender.com/api/v2/sent_faxes?page=1&page_size=10',
  CURLOPT_HTTPHEADER => ['Authorization: Bearer sk_test_...'],
  CURLOPT_RETURNTRANSFER => true
]);
$res = curl_exec($ch);
echo $res
```

#### Java

```java
import java.net.http.*;
import java.net.URI;
public class ListSent {
  public static void main(String[] args) throws Exception {
    var client = HttpClient.newHttpClient();
    var req = HttpRequest.newBuilder()
      .uri(URI.create("https://api.medsender.com/api/v2/sent_faxes?page=1&page_size=10"))
      .header("Authorization","Bearer sk_test_...")
      .build();
    var res = client.send(req, HttpResponse.BodyHandlers.ofString());
    System.out.println(res.body());
  }
}
```

#### C#

```csharp
using System;
using System.Net.Http;
var url = "https://api.medsender.com/api/v2/sent_faxes?page=1&page_size=10";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization","Bearer sk_test_...");
var res = await client.GetAsync(url);
Console.WriteLine(await res.Content.ReadAsStringAsync());
```

Response

```json
{
  "sent_faxes": [
    {
      "from_number": "+15550100001",
      "to_number": "+15550100002",
      "recipient_name": "Dr. Example",
      "record_status": "activated",
      "patient_name": "John Doe",
      "patient_dob": "1990-01-15",
      "send_token": "f5cfd99304f9",
      "sender_name": "Example Provider",
      "expiry": "2025-02-15T14:30:00.000Z",
      "view_count": 0,
      "note": "Referral documents",
      "sent_at": "2025-01-15T14:30:00.000Z",
      "completed_at": "2025-01-15T14:32:00.000Z",
      "sent_status": "success",
      "document_type": "both",
      "error_details": null,
      "num_pages": 3,
      "is_test": false
    }
  ],
  "meta": {
    "total_count": 42,
    "total_pages": 5,
    "per_page": 10,
    "page": 1
  }
}
```

Response Fields

| Field | Description |
| --- | --- |
| send_token | Unique identifier for this fax (use this to retrieve status) |
| from_number | The Medsender fax number that sent this fax |
| to_number | The destination fax number |
| sent_status | Fax delivery status: "queued", "inprogress", "success", or "failure" |
| sent_at | When the fax was queued for sending (ISO 8601) |
| completed_at | When the fax finished sending (ISO 8601, null if still in progress) |
| num_pages | Number of pages in the fax |
| error_details | Error information if sent_status is "failure", otherwise null |
| is_test | Whether this was sent using test credentials |
| patient_name | Patient name if provided when sending |
| patient_dob | Patient date of birth if provided |
| sender_name | Sender name if provided |
| recipient_name | Recipient name if provided |
| note | Internal note if provided (for your reference only) |
| record_status | Record status: "activated", "archived", or "revoked" |
| document_type | Document type: "both", "document_only", or "access_code_sheet_only" |
| expiry | When the secure link expires (30 days from creation) |
| view_count | Number of times the fax has been viewed via secure link |

## Get Sent Fax

GET `/sent_faxes/:id` — Retrieves details for a specific sent fax.

The `:id` parameter is the fax's `sendToken`.

#### cURL

```bash
curl -s -H "Authorization: Bearer sk_test_..." "https://api.medsender.com/api/v2/sent_faxes/REPLACE_SEND_TOKEN" | jq
```

#### Node

```javascript
const API_BASE='https://api.medsender.com/api/v2';
const API_KEY='sk_test_...';
const id='REPLACE_SEND_TOKEN';
const res=await fetch(`${API_BASE}/sent_faxes/${id}`,{headers:{Authorization:`Bearer ${API_KEY}`}});
console.log(await res.json());
```

#### TypeScript

```typescript
const API_BASE: string='https://api.medsender.com/api/v2';
const API_KEY: string='sk_test_...';
const id: string='REPLACE_SEND_TOKEN';
const res = await fetch(`${API_BASE}/sent_faxes/${id}`,{ headers:{ Authorization: `Bearer ${API_KEY}` }});
console.log(await res.json());
```

#### Python

```python
import requests
API_BASE='https://api.medsender.com/api/v2'
API_KEY='sk_test_...'
id='REPLACE_SEND_TOKEN'
r=requests.get(f"{API_BASE}/sent_faxes/{id}", headers={'Authorization':f'Bearer {API_KEY}'})
print(r.json())
```

#### Ruby

```ruby
require 'net/http'
require 'uri'
id='REPLACE_SEND_TOKEN'
uri = URI.parse("https://api.medsender.com/api/v2/sent_faxes/#{id}")
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer sk_test_...'
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true){|http| http.request(request)}
puts res.body
```

#### PHP

```php
<?php
$ch = curl_init();
$id = 'REPLACE_SEND_TOKEN';
curl_setopt_array($ch, [
  CURLOPT_URL => 'https://api.medsender.com/api/v2/sent_faxes/' . $id,
  CURLOPT_HTTPHEADER => ['Authorization: Bearer sk_test_...'],
  CURLOPT_RETURNTRANSFER => true
]);
$res = curl_exec($ch);
echo $res
```

#### Java

```java
import java.net.http.*;
import java.net.URI;
public class GetSent {
  public static void main(String[] args) throws Exception {
    var id = "REPLACE_SEND_TOKEN";
    var client = HttpClient.newHttpClient();
    var req = HttpRequest.newBuilder()
      .uri(URI.create("https://api.medsender.com/api/v2/sent_faxes/" + id))
      .header("Authorization","Bearer sk_test_...")
      .build();
    var res = client.send(req, HttpResponse.BodyHandlers.ofString());
    System.out.println(res.body());
  }
}
```

#### C#

```csharp
using System;
using System.Net.Http;
var id = "REPLACE_SEND_TOKEN";
var url = "https://api.medsender.com/api/v2/sent_faxes/" + id;
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization","Bearer sk_test_...");
var res = await client.GetAsync(url);
Console.WriteLine(await res.Content.ReadAsStringAsync());
```

Response

```json
{
  "from_number": "+15550100001",
  "to_number": "+15550100002",
  "recipient_name": "Dr. Example",
  "record_status": "activated",
  "patient_name": "John Doe",
  "patient_dob": "1990-01-15",
  "send_token": "f5cfd99304f9",
  "sender_name": "Example Provider",
  "expiry": "2025-02-15T14:30:00.000Z",
  "view_count": 2,
  "note": "Referral documents",
  "sent_at": "2025-01-15T14:30:00.000Z",
  "completed_at": "2025-01-15T14:32:00.000Z",
  "sent_status": "success",
  "document_type": "both",
  "error_details": null,
  "num_pages": 3,
  "is_test": false
}
```

## Send Fax

POST `/sent_faxes` — Sends a fax using multipart form data.

Request Parameters

| Parameter | Required | Description |
| --- | --- | --- |
| file | Yes | PDF or TIFF file to send |
| from_number | Yes | Your Medsender fax number (E.164 format, e.g. +15550100001) |
| to_number | Yes | Destination fax number (E.164 format) |
| callback_url | No | URL to receive status callback when fax completes |
| patient_name | No | Patient name for record keeping |
| patient_dob | No | Patient date of birth (YYYY-MM-DD) |
| sender_name | No | Name of the person/org sending the fax |
| recipient_name | No | Name of the intended recipient |
| note | No | Internal note for your reference (not sent in fax) |
| document_type | No | Type of document: "both" (default), "document_only", or "access_code_sheet_only" |

#### cURL

```bash
export API_BASE="https://api.medsender.com/api/v2"
export API_KEY="sk_test_..."

curl -s -X POST -H "Authorization: Bearer $API_KEY" \
  -F "file=@./sample.pdf" \
  -F "from_number=+14155550100" \
  -F "to_number=+13125550123" \
  "$API_BASE/sent_faxes"
```

#### Node

```javascript
import { readFile } from 'fs/promises';

const API_BASE = 'https://api.medsender.com/api/v2';
const API_KEY = 'sk_test_...';
const fd = new FormData();
const fileBuffer = await readFile('./sample.pdf');
fd.append('file', new Blob([fileBuffer]), 'sample.pdf');
fd.append('from_number', '+14155550100');
fd.append('to_number', '+13125550123');
const res = await fetch(`${API_BASE}/sent_faxes`, { method: 'POST', headers: { Authorization: `Bearer ${API_KEY}` }, body: fd });
console.log(await res.json());
```

#### TypeScript

```typescript
const API_BASE = 'https://api.medsender.com/api/v2';
const API_KEY: string = 'sk_test_...';
const fd = new FormData();
fd.append('file', new Blob([await (await fetch('./sample.pdf')).arrayBuffer()]), 'sample.pdf');
fd.append('from_number','+14155550100');
fd.append('to_number','+13125550123');
const res = await fetch(`${API_BASE}/sent_faxes`,{ method:'POST', headers:{ Authorization:`Bearer ${API_KEY}` }, body: fd });
console.log(await res.json());
```

#### Python

```python
import requests
API_BASE='https://api.medsender.com/api/v2'
API_KEY='sk_test_...'
files={'file':open('./sample.pdf','rb')}
data={'from_number':'+14155550100','to_number':'+13125550123'}
r=requests.post(f"{API_BASE}/sent_faxes", headers={'Authorization':f'Bearer {API_KEY}'}, files=files, data=data)
print(r.json())
```

#### Ruby

```ruby
require 'net/http'
require 'uri'

uri = URI.parse('https://api.medsender.com/api/v2/sent_faxes')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer sk_test_...'
form_data = [
  ['file', File.open('sample.pdf')],
  ['from_number', '+14155550100'],
  ['to_number', '+13125550123']
]
request.set_form(form_data, 'multipart/form-data')
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
puts res.body
```

#### PHP

```php
<?php
$ch = curl_init();
$post = [ 'file' => new CURLFile('sample.pdf','application/pdf','sample.pdf'), 'from_number' => '+14155550100', 'to_number' => '+13125550123' ];
curl_setopt_array($ch, [
  CURLOPT_URL => 'https://api.medsender.com/api/v2/sent_faxes',
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => ['Authorization: Bearer sk_test_...'],
  CURLOPT_POSTFIELDS => $post,
  CURLOPT_RETURNTRANSFER => true
]);
$res = curl_exec($ch);
echo $res
```

#### Java

```java
import java.net.http.*;
import java.net.URI;
import java.nio.file.*;
import java.util.*;

public class SendFax {
  public static void main(String[] args) throws Exception {
    var boundary = UUID.randomUUID().toString();
    var client = HttpClient.newHttpClient();

    // Build multipart body
    var fileBytes = Files.readAllBytes(Path.of("sample.pdf"));
    var body = new StringBuilder();
    body.append("--").append(boundary).append("\r\n");
    body.append("Content-Disposition: form-data; name=\"file\"; filename=\"sample.pdf\"\r\n");
    body.append("Content-Type: application/pdf\r\n\r\n");
    var prefix = body.toString().getBytes();
    var suffix = ("\r\n--" + boundary + "\r\n" +
      "Content-Disposition: form-data; name=\"from_number\"\r\n\r\n+14155550100\r\n--" + boundary + "\r\n" +
      "Content-Disposition: form-data; name=\"to_number\"\r\n\r\n+13125550123\r\n--" + boundary + "--\r\n").getBytes();

    var fullBody = new byte[prefix.length + fileBytes.length + suffix.length];
    System.arraycopy(prefix, 0, fullBody, 0, prefix.length);
    System.arraycopy(fileBytes, 0, fullBody, prefix.length, fileBytes.length);
    System.arraycopy(suffix, 0, fullBody, prefix.length + fileBytes.length, suffix.length);

    var req = HttpRequest.newBuilder()
      .uri(URI.create("https://api.medsender.com/api/v2/sent_faxes"))
      .header("Authorization", "Bearer sk_test_...")
      .header("Content-Type", "multipart/form-data; boundary=" + boundary)
      .POST(HttpRequest.BodyPublishers.ofByteArray(fullBody))
      .build();
    var res = client.send(req, HttpResponse.BodyHandlers.ofString());
    System.out.println(res.body());
  }
}
```

#### C#

```csharp
using System;
using System.Net.Http;
using System.Threading.Tasks;

var api = "https://api.medsender.com/api/v2/sent_faxes";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer sk_test_...");
using var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(System.IO.File.ReadAllBytes("sample.pdf")), "file", "sample.pdf");
form.Add(new StringContent("+14155550100"), "from_number");
form.Add(new StringContent("+13125550123"), "to_number");
var res = await client.PostAsync(api, form);
Console.WriteLine(await res.Content.ReadAsStringAsync());
```

Response

```json
{
  "message": "Record has been sent, we will send a callback upon completion.",
  "fax_id": "f5cfd99304f9"
}
```
