The PactSafe Developer Hub

Welcome to the PactSafe developer hub. You'll find comprehensive guides and documentation to help you start working with PactSafe as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Guides

Using PS.js with back-end API calls

You may want to use PS.js to render the contracts on the page, populate a contract with app data, and more—but send the API call on the back-end. Here's how to do it!

In this article, we'll cover how you can use the JavaScript library in tandem with our API to send acceptance of a contract or contracts on the back-end. You'll learn how to:

  • Load PS.js and render the contract on the page
  • Set the Signer ID of the signer programmatically
  • Disable sending when the checkbox on a click-through agreement is clicked
  • Send the payload that would be sent automatically to your back-end.

What you need

In order to complete this article, you'll need the following already working:

  • A published Contract that's been marked "Public"
  • A published Group with a Group Key
  • Working knowledge of JavaScript and of PS.js

Why should I do this?

By default, when you load an embedded contract onto a page, we'll automatically send acceptance of a contract as soon as your signer checks the box. Some people don't want to do this, so we've got a couple of different ways to handle sending acceptance. Below you can see our proposed flow for:

  1. Loading PS.js and embedding the contracts into your page, which will dynamically grab the right contracts and versions and inject them into the page.
  2. Send acceptance after a user completes the form using the Activity API.

Loading the embedded contract

To get the contract loaded into your page, simply use the snippet below and swap out with your own Site Access ID (found here) and your Group Key (found in your Group):

Notice the line in the embed code above that disables sending of the acceptance automatically:

_ps('create', 'eebbf489-fb84-4a0c-b624-51f2ead3104b', { disable_sending: true });

Sending acceptance manually

Disabling sending will prevent the acceptance from being sent automatically, so you'll need to send acceptance manually. One way to do this is as so:

_ps('set', 'signer_id', '[email protected]');

// send manually by overriding the disable_sending parameter
_ps('group-key:send', 'agreed', { disable_sending: false });

Sending acceptance on the back-end

Instead of sending acceptance in JavaScript, you can send acceptance on the back-end of your application on the server-side. This can enhance the security of your app and integration by not allowing for anything to be sent client-side in JavaScript.

The best way to do this is to grab the payload of the user and passing it into a hidden input field that's passed to the back-end or interstitial page that sits between your form and the redirect that the user is directed to after completing the form:

// set the payload that would be send in PS.js to a hidden variable


Then, all you have to do on your back-end is an HTTP POST to and append the getPayload value as a query string:


  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "" . $_POST['payload']);
  curl_setopt($ch, CURLOPT_HEADER, FALSE);
  $response = curl_exec($ch);


Updated about a year ago

What's Next

Get more dynamic in how you load and track acceptance on embedded contracts:

How to use Dynamic Contracts with the Javascript Library
Dynamic Groups (and how to use them)

Using PS.js with back-end API calls

You may want to use PS.js to render the contracts on the page, populate a contract with app data, and more—but send the API call on the back-end. Here's how to do it!

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.