Skip to content

ToBase64

Returns the raw response bytes encoded as Base64.

1
myRestResponse.ToBase64():string

Returns

The response body as a Base64 string, or an empty string if there is no body.

Remarks

Use this method for binary content such as PDF files or images.

Examples

Attach a downloaded file to an e-mail

1
2
3
4
5
6
7
8
9
var pdf = $Rest.Create('https://api.example.com/')
    .Request('invoices/{id}/pdf')
    .AddUrlParameter('id', $Xml.Evaluate('InvoiceId'))
    .Get()
    .ToBase64();

$Messages.New($Xml.Evaluate('Customer/EMailAddress'), 'Your invoice', 'Please find your invoice attached.')
    .Attach('Invoice.pdf', 'application/pdf', pdf)
    .Send();