First steps with fax
Learn how to send and receive your first fax using SignalWire. You'll configure a phone number, create SWML or cXML scripts to handle faxes, and use SWML or our APIs to send faxes programmatically.
Prerequisites
Before you begin, you'll need:
- A SignalWire account
- At least one phone number capable of receiving faxes
- Your API credentials (Space URL, Project ID, and API token)
Receiving your first fax
To receive faxes, you'll configure a phone number to handle incoming faxes using either a SWML or cXML script that defines what happens when a fax arrives.
Below are examples of how to set up your fax handler with SWML or cXML.
If you prefer to host the fax handling logic yourself, you have two options:
- For SWML: Configure a webhook endpoint that returns SWML. See our SWML receive_fax documentation for more details.
- For cXML: Use our Compatibility SDKs. See our
<Receive>
verb documentation for code examples.
You'll need to make your code accessible to SignalWire through a webhook. We have a guide on testing webhooks with ngrok to help you get started.
Sending your first fax
A fax can be sent by utilizing SWML, the Compatibility REST API, or the Compatibility SDK.
Using SWML
SWML can be used to send a fax through the send_fax
method.
The below example script sends a fax, then posts the result to a predetermined webhook.
- YAML
- JSON
version: 1.0.0
sections:
main:
- send_fax:
document: https://example.com/fax_to_send.pdf
- execute:
dest: 'https://example.com/handle_outgoing_fax_result'
{
"version": "1.0.0",
"sections": {
"main": [
{
"send_fax": {
"document": "https://example.com/fax_to_send.pdf"
}
},
{
"execute": {
"dest": "https://example.com/handle_outgoing_fax_result"
}
}
]
}
}
Using the SignalWire REST API
You can also utilize SWML to send faxes via the SignalWire REST API's Create a Call endpoint
POST https://{Your_Space_Name}.signalwire.com/api/calling/calls
example body including required parameters:
- Using URL parameter
- Using inline SWML
{
"command": "dial",
"params": {
"from": "sip:from-sip@example-112233445566.sip.signalwire.com",
"to": "sip:from-sip@example-112233445567.sip.signalwire.com",
"url": "https://example.com/swml-for-faxing"
}
}
{
"command": "dial",
"params": {
"from": "sip:from-sip@example-112233445566.sip.signalwire.com",
"to": "sip:from-sip@example-112233445567.sip.signalwire.com",
"swml": "{"version":"1.0.0","sections":{"main":[{"send_fax":{"document":"https://example.com/fax_to_send.pdf"}},{"execute":{"dest":"https://example.com/handle_outgoing_fax_result"}}]}}"
}
}
Using the Compatibility REST API
Send a fax by making a POST request to the Compatibility API's Send Fax endpoint:
POST https://<YOUR_SPACE_URL>.signalwire.com/api/laml/2010-04-01/Accounts/<YOUR_PROJECT_ID>/Faxes
Required parameters:
From
- Your SignalWire phone numberTo
- The destination fax numberMediaUrl
- URL to the document you want to send
Using the Compatibility SDK
You can also send faxes using our Compatibility SDK's Send a Fax function:
- JavaScript
- Python
- .NET
- PHP
- Ruby
const { RestClient } = require("@signalwire/compatibility-api");
const client = RestClient("YourProjectID", "YourAuthToken", {
signalwireSpaceUrl: "example.signalwire.com",
});
client.fax.faxes
.create({
from: "+13103383454",
to: "+13104456789",
mediaUrl: "https://example.com/fax.pdf",
})
.then((fax) => console.log(fax.sid))
.done();
from signalwire.rest import Client as signalwire_client
client = signalwire_client("YourProjectID", "YourAuthToken", signalwire_space_url = 'example.signalwire.com')
fax = client.fax.faxes \
.create(
from_='+13103383454',
to='+13104456789',
media_url='https://example.com/fax.pdf'
)
print(fax.sid)
using System;
using System.Collections.Generic;
using Twilio;
using Twilio.Rest.Fax.V1;
class Program
{
static void Main(string[] args)
{
TwilioClient.Init("YourProjectID", "YourAuthToken", new Dictionary<string, object> { ["signalwireSpaceUrl"] = "<your-domain>.signalwire.com" });
var fax = FaxResource.Create(
from: "+13103383454",
to: "+13104456789",
mediaUrl: new Uri("https://example.com/fax.pdf")
);
Console.WriteLine(fax.Sid);
}
}
<?php
use SignalWire\Rest\Client;
$client = new Client('YourProjectID', 'YourAuthToken', array("signalwireSpaceUrl" => "example.signalwire.com"));
$fax = $client->fax->v1->faxes
->create("+13104456789", // to
"https://example.com/fax.pdf", // mediaUrl
array("from" => "+13103383454")
);
print($fax->sid);
?>
require 'signalwire/sdk'
@client = Signalwire::REST::Client.new 'YourProjectID', 'YourAuthToken', signalwire_space_url: "example.signalwire.com"
fax = @client.fax.faxes
.create(
from: '+13103383454',
to: '+13104456789',
media_url: 'https://example.com/fax.pdf'
)
puts fax.sid
In the Legacy Dashboard
No Resources tab? Your SignalWire Space is on the Legacy Dashboard.
Expand the section below to view this guide's Legacy instructions.