Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Latest commit

 

History

History
129 lines (101 loc) · 3.36 KB

README.md

File metadata and controls

129 lines (101 loc) · 3.36 KB

PrimeTrustV2 Node

PrimeTrust V2 Node Client.

API Documentation

Installation

primetrust-v2 is available on NPM.

npm i primetrust-v2 --save

API Resources

Check the complete list of common use cases for the Primetrust API.

Getting started

var Client = require("primetrust-v2").Client;

const primetrust = new Client({
    userId: process.env.PRIMETRUST_SERVICE_USER_UUID, // optional UUIDv4 use as X-Idempotent-ID
    username: process.env.PRIMETRUST_SERVICE_USERNAME,
    password: process.env.PRIMETRUST_SERVICE_PASSWORD,
    environment: "sandbox" // defaults to 'sandbox'
});

The previous code allows you to integrate with Primetrust solutions and does the following actions:

  • Creates a service user.
  • Creates a JWT for the user authentication.
  • Creates a class abstraction that allows you to call the API.

Making requests

Once you've created a Client, you can make requests using the #get, #post, and #delete methods. These methods return promises containing a response object detailed in the Responses section.

// GET Method
primetrust
  .get("/v2/users")
  .then((res) => console.log(res));

// POST Method
primetrust
  .post("/v2/users",
    {
      "data": {
        "type": "users",
        "attributes": {
          "name": "api_test",
          "email": "[email protected]",
          "password": "api_Test11"  //must contain at least one lowercase letter, uppercase letter, and digit and must be at least eight characters in length.
        }
      }
    })
  .then((res) => console.log(res));

// PATCH Method
Primetrust
  .patch(`/v2/accounts/${account_UUID}/sandbox`,
    {
      "data": {
        "type": "accounts",
        "attributes": {
          "name": "updated_company_name"
        }
      }
    })
  .then((res) => console.log(res));

// DELETE Method
primetrust.delete(`/v2/contacts/${contact_UUID}`);

Setting headers

To set additional headers on a request you can pass an object as the 3rd argument.

For example:

primetrust
    .post(
        "/v2/agreement-previews",
        { 
            data: {
            type: "account",
            "attributes": {...account_attributes}
            } 
        },
        { "X-Idempotent-ID-V2": "a52fcf63-0730-41c3-96e8-7147b5d1fb01" }
    );

Responses

primetrust.get("/v2/users").then(
  function(res) {
    // res.status   => 200
    // res.headers  => Headers { ... }
    // res.body     => Object or String depending on response type
  },
  function(error) {
    // when the server return a status >= 400
    // error.status   => 400
    // error.headers  => Headers { ... }
    // error.body     => Object or String depending on response type
  }
);

Contributing

Bug reports and pull requests are welcome on Github.

Changelog

  • 1.1.5 Headers method expose due to the use case of uploaded documents form.
  • 1.1.4 Patch method added.
  • 1.1.1 Expiration token can be set using process.env.PRIMETRUST_TOKEN_EXPIRATION or set to 1hr by default.
  • 1.1.0 Token Manager Function reference fixed, pagination, filering and querying parse not working in query objects for get requests.