Link Search Menu Expand Document

PDF from Email

Description: Convert email files (MSG or EML) code into PDF. Extracts attachments (if any) from input email and embeds into PDF as pdf attachments.

Status Errors

CodeDescription
200The request has succeeded
400bad input parameters
401unauthorized
403not enough credits
405Timeout error. To process large documents or files please use asynchronous mode ( set async parameter to true) and then check the status using /job/check endpoint. If file contains many pages then specify a page range using pages parameter. The number of pages of the document can be obtained using the endpoint /pdf/info

Example

Sample Request:

! Don’t forget to set x-api-key url param or http header param (preferred) to API key, get yours here

Available methods

[POST] /pdf/convert/from/email

Generate PDF from MSG or EML file and creates PDF file with email and attachments (if any). You can set the following params:

  • url required. Link to input EML or MSG file to be converted. You can pass link to file from Google Drive, Dropbox or another online file service that can generate shareable links. You can also use built-in PDF.co cloud storage located at https://app.pdf.co/files or upload your file as temporary file right before making this API call (see Upload and Manage Files section for more details on uploading files via API).
  • embedAttachments optional. True by default. Set to true to automatically embeds all attachments from original input email MSG or EML fileas files into final output PDF. Set to false if you don’t want to embed attachments so it will convert only the body of input email.
  • convertAttachments optional. true by default. Set to false if you don’t want to convert attachments from original email and want to embed them as original files (as embedded pdf attachments). Converts attachments that are supported by API (doc, docx, html, png, jpg etc) into PDF and merges into output final PDF. Non-supported file types are added as PDF attachments (Adobe Reader or another viewer maybe required to view PDF attachments).
  • async optional. Set to true to run as async job in background (recommended for heavy documents).
  • margins optional. set to css style margins like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px (the order of margins is top, right, bottom, left).
  • paperSize optional. Can be Letter, A4, A5, A6 or custom size in pixels, mm or inches with width and height separated by space like this: 200 300, 200px 300px, 200mm 300mm, 20cm 30cm or 6in 8in.
  • orientation optional. set to Portrait or Landscape. Portrait by default.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.

Description

  • Method: POST
  • URL: /v1/pdf/convert/from/email

Query parameters

No query parameters accepted.

Body payload

{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
    "embedAttachments": true,
    "convertAttachments": true,
    "paperSize": "Letter",    
    "name": "email-with-attachments",
    "async": false,
    "encrypt": false
}

Example responses

JSON POST /pdf/convert/from/url
{
    "url": "https://pdf-temp-files.s3.amazonaws.com/980bc13f061344809c75e83ce181851c/Contact_us.pdf",
    "pageCount": 3,
    "error": false,
    "status": 200,
    "name": "Contact_us.pdf",
    "remainingCredits": 60637
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/from/email' \
--header 'x-api-key: ' \
--header 'Content-Type: application/json' \
--data-raw '{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
    "embedAttachments": true,
    "convertAttachments": true,
    "paperSize": "Letter",    
    "name": "email-with-attachments",
    "async": false,
    "encrypt": false
}'
JavaScript
var myHeaders = new Headers();
myHeaders.append("x-api-key", "");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
 "embedAttachments": true,
 "convertAttachments": true,
 "paperSize": "Letter",
 "name": "email-with-attachments",
 "async": false,
 "encrypt": false
});

var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
};

fetch("https://api.pdf.co/v1/pdf/convert/from/email", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));
NodeJs
var request = require('request');
var options = {
	'method': 'POST',
	'url': 'https://api.pdf.co/v1/pdf/convert/from/email',
	'headers': {
		'x-api-key': '',
		'Content-Type': 'application/json'
	},
	body: JSON.stringify({
	 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
	 "embedAttachments": true,
	 "convertAttachments": true,
	 "paperSize": "Letter",
	 "name": "email-with-attachments",
	 "async": false,
	 "encrypt": false
	})

};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
	CURLOPT_URL => 'https://api.pdf.co/v1/pdf/convert/from/email',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS =>'{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
    "embedAttachments": true,
    "convertAttachments": true,
    "paperSize": "Letter",    
    "name": "email-with-attachments",
    "async": false,
    "encrypt": false
}',
	CURLOPT_HTTPHEADER => array(
		'x-api-key: ',
		'Content-Type: application/json'
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Java
import java.io.*;
import okhttp3.*;
public class main {
	public static void main(String []args) throws IOException{
		OkHttpClient client = new OkHttpClient().newBuilder()
			.build();
		MediaType mediaType = MediaType.parse("application/json");
		RequestBody body = RequestBody.create(mediaType, "{\n    \"url\": \"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml\",\n    \"embedAttachments\": true,\n    \"convertAttachments\": true,\n    \"paperSize\": \"Letter\",    \n    \"name\": \"email-with-attachments\",\n    \"async\": false,\n    \"encrypt\": false\n}");
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/pdf/convert/from/email")
			.method("POST", body)
			.addHeader("x-api-key", "")
			.addHeader("Content-Type", "application/json")
			.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}
}

C#
using System;
using RestSharp;
namespace HelloWorldApplication {
	class HelloWorld {
		static void Main(string[] args) {
			var client = new RestClient("https://api.pdf.co/v1/pdf/convert/from/email");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("x-api-key", "");
			request.AddHeader("Content-Type", "application/json");
			var body = @"{" + "\n" +
			@"    ""url"": ""https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml""," + "\n" +
			@"    ""embedAttachments"": true," + "\n" +
			@"    ""convertAttachments"": true," + "\n" +
			@"    ""paperSize"": ""Letter"",    " + "\n" +
			@"    ""name"": ""email-with-attachments""," + "\n" +
			@"    ""async"": false," + "\n" +
			@"    ""encrypt"": false" + "\n" +
			@"}";
			request.AddParameter("application/json", body,  ParameterType.RequestBody);
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests
import json

url = "https://api.pdf.co/v1/pdf/convert/from/email"

payload = json.dumps({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
 "embedAttachments": True,
 "convertAttachments": True,
 "paperSize": "Letter",
 "name": "email-with-attachments",
 "async": False,
 "encrypt": False
})
headers = {
	'x-api-key': '',
	'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("x-api-key", "")
$headers.Add("Content-Type", "application/json")

$body = "{`n    `"url`": `"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml`",`n    `"embedAttachments`": true,`n    `"convertAttachments`": true,`n    `"paperSize`": `"Letter`",    `n    `"name`": `"email-with-attachments`",`n    `"async`": false,`n    `"encrypt`": false`n}"

$response = Invoke-RestMethod 'https://api.pdf.co/v1/pdf/convert/from/email' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

[POST] /pdf/convert/from/email with Orientation and paper Size

  • url required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.

profiles string may contain JSON string containing options like orientation, paper size, margins. Example: {'orientation': 'landscape', 'paperSize': 'letter', 'margins': '5mm'}

Available options inside profiles:

  • margins optional. set to css style margins like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px (the order of margins is top, right, bottom, left).
  • paperSize optional. Can be Letter, A4, A5, A6 or custom size in pixels, mm or inches with width and height separated by space like this: 200 300, 200px 300px, 200mm 300mm, 20cm 30cm or 6in 8in.
  • orientation optional. set to Portrait or Landscape. Portrait by default.

Description

  • Method: POST
  • URL: /v1/pdf/convert/from/email

Query parameters

No query parameters accepted.

Body payload

{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
    "embedAttachments": true,
    "name": "email-with-attachments",
    "async": false,
    "encrypt": false,
    "profiles": "{\"orientation\": \"landscape\", \"paperSize\": \"letter\" }"
}

Example responses

/pdf/convert/from/email with Orientation and paper Size
{
    "url": "https://pdf-temp-files.s3.amazonaws.com/1baff39add874c509b2c2675ba7734fc/email-with-attachments.pdf",
    "pageCount": 3,
    "error": false,
    "status": 200,
    "name": "email-with-attachments",
    "remainingCredits": 616243,
    "credits": 168
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/from/email' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
    "embedAttachments": true,
    "name": "email-with-attachments",
    "async": false,
    "encrypt": false,
    "profiles": "{\"orientation\": \"landscape\", \"paperSize\": \"letter\" }"
}'
JavaScript
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "");

var raw = JSON.stringify({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
 "embedAttachments": true,
 "name": "email-with-attachments",
 "async": false,
 "encrypt": false,
 "profiles": "{\"orientation\": \"landscape\", \"paperSize\": \"letter\" }"
});

var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
};

fetch("https://api.pdf.co/v1/pdf/convert/from/email", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));
NodeJs
var request = require('request');
var options = {
	'method': 'POST',
	'url': 'https://api.pdf.co/v1/pdf/convert/from/email',
	'headers': {
		'Content-Type': 'application/json',
		'x-api-key': ''
	},
	body: JSON.stringify({
	 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
	 "embedAttachments": true,
	 "name": "email-with-attachments",
	 "async": false,
	 "encrypt": false,
	 "profiles": "{\"orientation\": \"landscape\", \"paperSize\": \"letter\" }"
	})

};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
	CURLOPT_URL => 'https://api.pdf.co/v1/pdf/convert/from/email',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS =>'{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
    "embedAttachments": true,
    "name": "email-with-attachments",
    "async": false,
    "encrypt": false,
    "profiles": "{\\"orientation\\": \\"landscape\\", \\"paperSize\\": \\"letter\\" }"
}',
	CURLOPT_HTTPHEADER => array(
		'Content-Type: application/json',
		'x-api-key: '
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Java
import java.io.*;
import okhttp3.*;
public class main {
	public static void main(String []args) throws IOException{
		OkHttpClient client = new OkHttpClient().newBuilder()
			.build();
		MediaType mediaType = MediaType.parse("application/json");
		RequestBody body = RequestBody.create(mediaType, "{\n    \"url\": \"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml\",\n    \"embedAttachments\": true,\n    \"name\": \"email-with-attachments\",\n    \"async\": false,\n    \"encrypt\": false,\n    \"profiles\": \"{\\\"orientation\\\": \\\"landscape\\\", \\\"paperSize\\\": \\\"letter\\\" }\"\n}");
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/pdf/convert/from/email")
			.method("POST", body)
			.addHeader("Content-Type", "application/json")
			.addHeader("x-api-key", "")
			.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}
}

C#
using System;
using RestSharp;
namespace HelloWorldApplication {
	class HelloWorld {
		static void Main(string[] args) {
			var client = new RestClient("https://api.pdf.co/v1/pdf/convert/from/email");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("Content-Type", "application/json");
			request.AddHeader("x-api-key", "");
			var body = @"{" + "\n" +
			@"    ""url"": ""https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml""," + "\n" +
			@"    ""embedAttachments"": true," + "\n" +
			@"    ""name"": ""email-with-attachments""," + "\n" +
			@"    ""async"": false," + "\n" +
			@"    ""encrypt"": false," + "\n" +
			@"    ""profiles"": ""{\""orientation\"": \""landscape\"", \""paperSize\"": \""letter\"" }""" + "\n" +
			@"}";
			request.AddParameter("application/json", body,  ParameterType.RequestBody);
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests
import json

url = "https://api.pdf.co/v1/pdf/convert/from/email"

payload = json.dumps({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
 "embedAttachments": True,
 "name": "email-with-attachments",
 "async": False,
 "encrypt": False,
 "profiles": "{\"orientation\": \"landscape\", \"paperSize\": \"letter\" }"
})
headers = {
	'Content-Type': 'application/json',
	'x-api-key': ''
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("x-api-key", "")

$body = "{`n    `"url`": `"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml`",`n    `"embedAttachments`": true,`n    `"name`": `"email-with-attachments`",`n    `"async`": false,`n    `"encrypt`": false,`n    `"profiles`": `"{`\`"orientation`\`": `\`"landscape`\`", `\`"paperSize`\`": `\`"letter`\`" }`"`n}"

$response = Invoke-RestMethod 'https://api.pdf.co/v1/pdf/convert/from/email' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

[POST] /email/decode

  • url required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.

Description

  • Method: POST
  • URL: /v1/email/decode

Query parameters

No query parameters accepted.

Body payload

{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
}

Example responses

/email/decode
{
    "body": {
        "from": "test@example.com",
        "fromName": "",
        "to": [
            {
                "address": "test2@example.com",
                "name": ""
            }
        ],
        "cc": [],
        "bcc": [],
        "sentAt": null,
        "receivedAt": null,
        "subject": "Test email with attachments",
        "bodyHtml": null,
        "bodyText": "Test Email Message with 2 PDF files as attachments\r\n\r\n",
        "attachmentCount": 2
    },
    "error": false,
    "status": 200,
    "name": "sample.json",
    "remainingCredits": 60095
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/email/decode' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
}'
JavaScript
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "");

var raw = JSON.stringify({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
});

var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
};

fetch("https://api.pdf.co/v1/email/decode", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));
NodeJs
var request = require('request');
var options = {
	'method': 'POST',
	'url': 'https://api.pdf.co/v1/email/decode',
	'headers': {
		'Content-Type': 'application/json',
		'x-api-key': ''
	},
	body: JSON.stringify({
	 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
	})

};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
	CURLOPT_URL => 'https://api.pdf.co/v1/email/decode',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS =>'{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
}',
	CURLOPT_HTTPHEADER => array(
		'Content-Type: application/json',
		'x-api-key: '
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Java
import java.io.*;
import okhttp3.*;
public class main {
	public static void main(String []args) throws IOException{
		OkHttpClient client = new OkHttpClient().newBuilder()
			.build();
		MediaType mediaType = MediaType.parse("application/json");
		RequestBody body = RequestBody.create(mediaType, "{\n    \"url\": \"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml\"\n}");
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/email/decode")
			.method("POST", body)
			.addHeader("Content-Type", "application/json")
			.addHeader("x-api-key", "")
			.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}
}

C#
using System;
using RestSharp;
namespace HelloWorldApplication {
	class HelloWorld {
		static void Main(string[] args) {
			var client = new RestClient("https://api.pdf.co/v1/email/decode");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("Content-Type", "application/json");
			request.AddHeader("x-api-key", "");
			var body = @"{" + "\n" +
			@"    ""url"": ""https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml""" + "\n" +
			@"}";
			request.AddParameter("application/json", body,  ParameterType.RequestBody);
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests
import json

url = "https://api.pdf.co/v1/email/decode"

payload = json.dumps({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
})
headers = {
	'Content-Type': 'application/json',
	'x-api-key': ''
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("x-api-key", "")

$body = "{`n    `"url`": `"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml`"`n}"

$response = Invoke-RestMethod 'https://api.pdf.co/v1/email/decode' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

[POST] /email/extract-attachments

  • url required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.

Description

  • Method: POST
  • URL: /v1/email/extract-attachments

Query parameters

No query parameters accepted.

Body payload

{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
}

Example responses

POST /email/extract-attachments
{
    "body": {
        "from": "test@example.com",
        "subject": "Test email with attachments",
        "bodyHtml": null,
        "bodyText": "Test Email Message with 2 PDF files as attachments\r\n\r\n",
        "attachments": [
            {
                "filename": "DigitalOcean.pdf",
                "url": "https://pdf-temp-files.s3.amazonaws.com/2943e6bb80e646ec92e839292e95d542/DigitalOcean.pdf"
            },
            {
                "filename": "sample.pdf",
                "url": "https://pdf-temp-files.s3.amazonaws.com/e10e37fbb438432a83ece50ccdc719b3/sample.pdf"
            }
        ]
    },
    "pageCount": 2,
    "error": false,
    "status": 200,
    "name": "sample.json",
    "remainingCredits": 60085
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/email/extract-attachments' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
}'
JavaScript
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "");

var raw = JSON.stringify({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
});

var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
};

fetch("https://api.pdf.co/v1/email/extract-attachments", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));
NodeJs
var request = require('request');
var options = {
	'method': 'POST',
	'url': 'https://api.pdf.co/v1/email/extract-attachments',
	'headers': {
		'Content-Type': 'application/json',
		'x-api-key': ''
	},
	body: JSON.stringify({
	 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
	})

};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
	CURLOPT_URL => 'https://api.pdf.co/v1/email/extract-attachments',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS =>'{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
}',
	CURLOPT_HTTPHEADER => array(
		'Content-Type: application/json',
		'x-api-key: '
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Java
import java.io.*;
import okhttp3.*;
public class main {
	public static void main(String []args) throws IOException{
		OkHttpClient client = new OkHttpClient().newBuilder()
			.build();
		MediaType mediaType = MediaType.parse("application/json");
		RequestBody body = RequestBody.create(mediaType, "{\n    \"url\": \"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml\"\n}");
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/email/extract-attachments")
			.method("POST", body)
			.addHeader("Content-Type", "application/json")
			.addHeader("x-api-key", "")
			.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}
}

C#
using System;
using RestSharp;
namespace HelloWorldApplication {
	class HelloWorld {
		static void Main(string[] args) {
			var client = new RestClient("https://api.pdf.co/v1/email/extract-attachments");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("Content-Type", "application/json");
			request.AddHeader("x-api-key", "");
			var body = @"{" + "\n" +
			@"    ""url"": ""https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml""" + "\n" +
			@"}";
			request.AddParameter("application/json", body,  ParameterType.RequestBody);
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests
import json

url = "https://api.pdf.co/v1/email/extract-attachments"

payload = json.dumps({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml"
})
headers = {
	'Content-Type': 'application/json',
	'x-api-key': ''
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("x-api-key", "")

$body = "{`n    `"url`": `"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml`"`n}"

$response = Invoke-RestMethod 'https://api.pdf.co/v1/email/extract-attachments' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json