Back to Website
Product Documentation Developers Integration Hub Create a Customer API User & Authenticate to the API

Create a Customer API User & Authenticate to the API

In this guide, we're going to take you through how you can create a customer API user and authenticate to the Kodaris API.

Video overview:

https://youtu.be/JPoQ4A_bG4E?si=HLGPANNEdWxvTudL

Create a Customer API User

1. Sign in to your Kodaris system as a customer

2279_sign_in_to_account.png

2. Navigate to the customer portal

2279_navigate_to_portal.png

3. Navigate to 'Employees' and click 'Add API User'

2279_2279_employees_api_user_2.png

4. In the popup window, enter your API user's name and, optionally, a description. Then click 'Create'

2279_2279_create_api_user_2.png

5. After your API user is created, be sure to copy and save the API key. This is the only time the API key will be shown. Once copied, click 'Set Permissions'

2279_2279_api_user_set_permissions_2.png

6. You should be redirected to the details screen for your new API user. Here, you'll want to scroll down to the 'Permissions' section and set the permissions for your API user.

2279_set_permissions.png

Your API user is all set! You can now authenticate to the Kodaris API.

Authenticate to the API

  1. Sign In
    • Call the endpoint: POST / api/user/customer/apiKeyLogin
      • Headers
        • Accept - application/json
        • Content-Type - application/json
      • Body
        • apiKey - the api key of your api user.
      • Response
        • A response will be returned indicating whether the login was successful or not. The response will also contain your userSessionApiKey that you will need to use on future requests to get responses back as a authenticated user.
  2. Fetch an Auth Token
    • You'll need an authorization token for any API requests you make to the Kodaris API.
    • Fetch one using the endpoint: GET / api/user/customer/authToken
      • Headers
        • Accept - application/json
        • Content-Type - application/json
        • userSessionApiKey - the userSessionApiKey from the /apiKeyLogin endpoint response
      • Response
        • The returned response will contain your auth token that you will need to use on future requests.
  3. Fetch Orders under your Company Account
    • In this example, we'll authenticate to the Kodaris API and fetch orders under your company account.
    • Send an API request to endpoint: POST api/account/order/list
      • Headers
        • Accept - application/json
        • Content-Type - application/json
        • userSessionApiKey - the userSessionApiKey from the /apiKeyLogin endpoint response
        • X-CSRF-TOKEN - the auth token from the /authToken endpoint response
      • Body
        • page - 0
          • Returns the first page of orders
        • size - 10
          • Returns a page with 10 orders
      • Response
        • A list of orders under your company account will be returned

Example

// Login to our account
var loginRes = kd.http.fetch({
  method: 'POST',
  url: 'https://content.kodaris.com/api/user/customer/apiKeyLogin',
  version: 2,
  body: {
    apiKey: 'xxxx'
  },
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
});

// keep our session token for future requests
var userSessionApiKey = loginRes.body.data.userSessionApiKey;

// get CRSF token for requests
var tokenRes = kd.http.fetch({
  method: 'GET',
  url: 'https://content.kodaris.com/api/user/customer/authToken',
  version: 2,
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'userSessionApiKey': userSessionApiKey
  }
});

// keep our token for future requests
var token = tokenRes.body.data;

// get orders under our company account
var orderRes = kd.http.fetch({
  method: 'POST',
  url: 'https://content.kodaris.com/api/account/order/list',
  version: 2,
  body: {
    page: 0,
    size: 10
  },
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'userSessionApiKey': userSessionApiKey,
    'X-CSRF-TOKEN': token
  }
});

kd.log('orderRes', orderRes);


-> response ->
{
    "status" : 200,
    "errors" : null,
    "body" : {
      "success" : true,
      "code" : 200,
      "messages" : { },
      "errors" : { },
      "data" : {
        "size" : 10,
        "number" : 0,
        "totalElements" : 431,
        "isLast" : false,
        "totalPages" : 44,
        "isFirst" : true,
        "hasPrevious" : false,
        "hasNext" : true,
        "numberOfElements" : 10,
        "offset" : null,
        "content" : {
          "0" : {
            "orderID" : 3137,
            "organization" : "Ocean Rd.",
            "firstName" : null,
            "lastName" : null,
            "email1" : "elizabeth@kodaris.com",
            "phone1" : "(123) 123-1234",
            "address1" : "123 Ocean Rd.",
            "address2" : "",
            "city" : "Some City",
            "state" : "CT",
            "postalCode" : "12345",
            "country" : "US",
            "countryName" : "US",
            "deliveryOrganization" : "Ocean Rd.",
            "deliveryFirstName" : null,
            "deliveryLastName" : null,
            "deliveryEmail1" : "elizabeth@kodaris.com",
            "deliveryPhone1" : "(123) 123-1234",
            "deliveryAddress1" : "123 Ocean Rd.",
            "deliveryAddress2" : null,
            "deliveryCity" : "Some City",
            "deliveryState" : "CT",
            "deliveryPostalCode" : "12345",
            "deliveryCountry" : "US",
            "deliveryCountryName" : "US",
            "completed" : null,
            "orderNumber" : null,
            "status" : "Initialized",
            "notes" : null,
            "purchaseOrder" : null,
            "extra5" : null,
            "shippingMethod" : null,
            "billingAddressCode" : "2088_3007billing_1",
            "deliveryAddressCode" : "2088_3007billing_1",
            "trackingNumber" : null,
            "customerID" : 1184,
            "companyID" : 473,
            "displayPricing" : true,
            "subtotal" : 63.04,
            "shipping" : null,
            "extraChargeTaxable" : null,
            "extraCharge" : null,
            "tax" : null,
            "total" : null
          },
          "1" : {
            "orderID" : 3231,
            "organization" : "Ocean Rd.",
            "firstName" : null,
            "lastName" : null,
            "email1" : "jane.doe@kodaris.com",
            "phone1" : "(123) 123-1234",
            "address1" : "123 Ocean Rd.",
            "address2" : "",
            "city" : "Some City",
            "state" : "CT",
            "postalCode" : "12345",
            "country" : "US",
            "countryName" : "US",
            "deliveryOrganization" : "Ocean Rd.",
            "deliveryFirstName" : null,
            "deliveryLastName" : null,
            "deliveryEmail1" : "jane.doe@kodaris.com",
            "deliveryPhone1" : "(123) 123-1234",
            "deliveryAddress1" : "123 Ocean Rd.",
            "deliveryAddress2" : null,
            "deliveryCity" : "Some City",
            "deliveryState" : "CT",
            "deliveryPostalCode" : "12345",
            "deliveryCountry" : "US",
            "deliveryCountryName" : "US",
            "completed" : null,
            "orderNumber" : null,
            "status" : "Initialized",
            "notes" : null,
            "purchaseOrder" : null,
            "extra5" : null,
            "shippingMethod" : null,
            "billingAddressCode" : "2088_3007billing_1",
            "deliveryAddressCode" : "2088_3007billing_1",
            "trackingNumber" : null,
            "customerID" : 1122,
            "companyID" : 473,
            "displayPricing" : true,
            "subtotal" : 105.93,
            "shipping" : null,
            "extraChargeTaxable" : null,
            "extraCharge" : null,
            "tax" : null,
            "total" : null
          }
... omitted for brevity
In this article