PandaDoc (pandadoc.com API v0.1.2) View Source

Documentation for PandaDoc which provides an API for pandadoc.com.

Installation

This package can be installed by adding pandadoc to your list of dependencies in mix.exs:

def deps do
  [{:pandadoc, "~> 0.1.2"}]
end

Configuration

Put the following lines into your config.exs or better, into your environment configuration files like test.exs, dev.exs or prod.exs.

config :pandadoc, api_key: "<your api key>"

WebHooks in Phoenix

Put the following lines in a file called pandadoc_controller.ex inside your controllers directory.

defmodule YourAppWeb.PandaDocController do
  use PandaDoc.PhoenixController

  def handle_document_change(id, status, _details) do
    id
    |> Documents.get_by_pandadoc_id!()
    |> Documents.update_document(%{status: status})
  end

  def handle_document_complete(id, pdf, status, _details) do
    id
    |> Documents.get_by_pandadoc_id!()
    |> Documents.update_document(%{data: pdf, status: status})
  end
end

Put the following lines into your router.ex and configure the WebHook in the pandadoc portal.

  post "/callbacks/pandadoc", YourAppWeb.PandaDocController, :webhook

Usage

iex> recipients = [
  %PandaDoc.Recipient{
    email: "jane@example.com",
    first_name: "Jane",
    last_name: "Example",
    role: "signer1"
  }
]

iex> PandaDoc.create_document("Sample PandaDoc PDF.pdf", [] = pdf_bytes, recipients)
{:ok, "msFYActMfJHqNTKH8YSvF1"}

Link to this section Summary

Functions

Get detailed data about a document such as name, status, dates, fields, metadata and much more.

Get basic data about a document such as name, status, and dates.

Download a signed PDF of a completed document.

List documents, optionally filter by a search query or tags.

Generates a link for the given recipient that you can just email or iframe with a validity of lifetime seconds (86400 by default).

Link to this section Functions

Link to this function

create_document(name, pdf_bytes, recipients, fields \\ %{}, tags \\ [], parse_form_fields \\ false, client \\ Connection.new())

View Source

Specs

create_document(
  String.t(),
  binary(),
  [PandaDoc.Model.Recipient.t()],
  map() | nil,
  [String.t()] | nil,
  boolean() | nil,
  Tesla.Env.client() | nil
) ::
  {:ok, String.t()}
  | {:ok, PandaDoc.Model.BasicDocumentResponse.t()}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

Creates a new Document from the given PDF file.

Parameters

  • name (String): Name of the document
  • pdf_bytes (Binary): PDF content
  • recipients ([PandaDoc.Model.Recipient]): Array of Recipients
  • fields (Map): [optional] Field-mappings for the PDF
  • tags ([String]): [optional] Array of Tags
  • parse_form_fields (Boolean): [optional] Should PandaDoc parse old-style PDF Fields?
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, document_id} on success
  • {:error, info} on failure

Examples

iex> pdf_bytes = File.read("/path/to/my.pdf")
iex> recipients = [
  %PandaDoc.Model.Recipient{email: "jane@example.com", first_name: "Jane", last_name: "Example", role: "signer1"}
]
iex> fields = %{
  name: %PandaDoc.Model.Field{value: "John", role: "signer1"}
}
iex> PandaDoc.create_document("Sample PandaDoc PDF.pdf", pdf_bytes, recipients, fields, ["tag1"])
{:ok, "msFYActMfJHqNTKH8YSvF1"}
Link to this function

delete_document(id, client \\ Connection.new())

View Source

Specs

delete_document(String.t(), Tesla.Env.client() | nil) ::
  {:ok, :atom}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

Delete a document.

Parameters

  • id (String): PandaDoc Document ID
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, :ok} on success
  • {:error, info} on failure

Examples

iex> PandaDoc.delete_document("msFYActMfJHqNTKH8YSvF1")
:ok
Link to this function

document_details(id, client \\ Connection.new())

View Source

Specs

document_details(String.t(), Tesla.Env.client() | nil) ::
  {:ok, PandaDoc.Model.DocumentResponse.t()}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

Get detailed data about a document such as name, status, dates, fields, metadata and much more.

Parameters

  • id (String): PandaDoc Document ID
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, %PandaDoc.Model.DocumentResponse{}} on success
  • {:error, info} on failure

Examples

iex> PandaDoc.document_details("msFYActMfJHqNTKH8YSvF1")
{:ok, %PandaDoc.Model.DocumentResponse{id: "msFYActMfJHqNTKH8YSvF1", status: "document.waiting_approval"}}
Link to this function

document_status(id, client \\ Connection.new())

View Source

Specs

document_status(String.t(), Tesla.Env.client() | nil) ::
  {:ok, PandaDoc.Model.BasicDocumentResponse.t()}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

Get basic data about a document such as name, status, and dates.

Parameters

  • id (String): PandaDoc Document ID
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, %PandaDoc.Model.BasicDocumentResponse{}} on success
  • {:error, info} on failure

Examples

iex> PandaDoc.document_status("msFYActMfJHqNTKH8YSvF1")
{:ok, %PandaDoc.Model.BasicDocumentResponse{id: "msFYActMfJHqNTKH8YSvF1", status: "document.waiting_approval"}}
Link to this function

download_document(id, query \\ [], client \\ Connection.new())

View Source

Specs

download_document(
  String.t(),
  keyword(String.t()) | nil,
  Tesla.Env.client() | nil
) ::
  {:ok, binary()}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

Download a PDF of any document.

Parameters

  • id (String): PandaDoc Document ID
  • query (Keywords): [optional] Query parameters for Watermarks
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, [] = pdf_bytes} on success
  • {:error, info} on failure

Examples

iex> PandaDoc.download_document("msFYActMfJHqNTKH8YSvF1", watermark_text: "WATERMARKED")
{:ok, []}
Link to this function

download_protected_document(id, query \\ [], client \\ Connection.new())

View Source

Specs

download_protected_document(
  String.t(),
  keyword(String.t()) | nil,
  Tesla.Env.client() | nil
) ::
  {:ok, binary()}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

Download a signed PDF of a completed document.

  • id (String): PandaDoc Document ID
  • query (Keywords): [optional] Query parameters for Watermarks
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, [] = pdf_bytes} on success
  • {:error, info} on failure

Examples

iex> PandaDoc.download_protected_document("msFYActMfJHqNTKH8YSvF1")
{:ok, []}
Link to this function

list_documents(query \\ [], client \\ Connection.new())

View Source

Specs

list_documents(keyword(String.t()) | nil, Tesla.Env.client() | nil) ::
  {:ok, PandaDoc.Model.DocumentListResponse.t()}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

List documents, optionally filter by a search query or tags.

Parameters

  • query (Keywords): [optional] Query parameters
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, [%PandaDoc.Model.BasicDocumentResponse{}} on success
  • {:error, info} on failure

Examples

iex> PandaDoc.list_documents()
{:ok, %PandaDoc.Model.DocumentListResponse{results: [%PandaDoc.Model.BasicDocumentResponse{}]}}
Link to this function

send_document(id, subject \\ nil, message \\ nil, silent \\ false, client \\ Connection.new())

View Source

Specs

send_document(
  String.t(),
  String.t() | nil,
  String.t() | nil,
  boolean() | nil,
  Tesla.Env.client() | nil
) ::
  {:ok, PandaDoc.Model.BasicDocumentResponse.t()}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

Move a document to sent status and send an optional email.

Parameters

  • id (String): PandaDoc Document ID
  • subject (String): [optional] E-Mail Subject
  • message (String): [optional] E-Mail Message
  • contact (PandaDoc.Model.CreateContact): Contact data
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, %PandaDoc.Model.BasicDocumentResponse{}} on success
  • {:error, info} on failure

Examples

iex> PandaDoc.send_document("msFYActMfJHqNTKH8YSvF1", "Document ready", "Hi there, please sign this document")
{:ok, %PandaDoc.Model.BasicDocumentResponse{id: "msFYActMfJHqNTKH8YSvF1", status: "document.sent"}}
Link to this function

share_document(id, recipient_email, lifetime \\ 86400, client \\ Connection.new())

View Source

Specs

share_document(
  String.t(),
  String.t(),
  integer() | nil,
  Tesla.Env.client() | nil
) ::
  {:ok, String.t(), DateTime.t()}
  | {:ok, PandaDoc.Model.ErrorResponse.t()}
  | {:error, Tesla.Env.t()}

Generates a link for the given recipient that you can just email or iframe with a validity of lifetime seconds (86400 by default).

Parameters

  • id (String): PandaDoc Document ID
  • recipient_email (String): Recipient E-Mail Address
  • lifetime (Integer): [optional] Seconds for this Link to be valid. Defaults to 86_400.
  • connection (PandaDoc.Connection): [optional] Connection to server

Returns

  • {:ok, "https://app.pandadoc.com/s/.." = url, ~U[2021-01-23 06:40:00] = expires} on success
  • {:error, info} on failure

Examples

iex> PandaDoc.share_document("msFYActMfJHqNTKH8YSvF1", "jane@example.com", 900)
{:ok, "https://app.pandadoc.com/s/msFYActMfJHqNTKH8YSvF1", expires_at: ~U[2017-08-29T22:18:44.315Z]}