Back to Website
Product Documentation Developers Integration Hub Customer API - Preview Creating an Order

Customer API - Preview Creating an Order

In this guide, we're going to take you through how you can preview creating an order through the Kodaris API.

Video overview:

https://www.youtube.com/watch?v=ByTRoDuxnm4
  1. Sign In
    • First, you will want to sign in to an account through the API.
    • 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. Preview Creating an Order
    • Now you can preview creating an order
    • Send an API request to endpoint: POST api/account/order
      • 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
      • Query Parameters
        • completeOrder - false
      • Body
        • For the payload, include a JSON object of the order you would like to preview creating. See the example below for a full sample along with comments describing each field.
      • Response
        • The returned response will be a preview of your order, including order totals, taxes and other charges.

Sample Payload

{
  notes: "Please deliver the order between 9AM and 7PM",

    // The purchase order number that will be used to place your order via PO.
    // Based on how your account is configured, the purchase order number may be optional.
    purchaseOrder: "MY-PO-NUMBER",

    // Billing address
    organization: "Kodaris",
    firstName: "John",
    lastName: "Smith",
    phone1: "1234567890",
    email1: "john.smith@kodaris.com",
    address1: "123 Some Address",
    address2: "Suite 2",
    city: "Atlanta",
    state: "GA",
    postalCode: "1234",
    country: "US",

    // The shipto the order should be attached to.
    // You can exclude this field if shipto is optional for your account.
    // If you do not include the shipto, your order will be placed as a one time only order
    deliveryAddressCode: "5043232_11_atlanta",

    // Delivery address; if you provide a shipto to attach the order to, you do not need to
    // provide the delivery address fields as they will be taken off the specified shipto
    // by default. If you are allowed override the shipto, you can include these delivery
    // address fields and they will be copied onto the order.
    deliveryOrganization: "Kodaris",
    deliveryAddress1: "123 Some Address",
    deliveryAddress2: "Suite 2",
    deliveryCity: "Atlanta",
    deliveryState: "GA",
    deliveryPostalCode: "1234",
    deliveryCountry: 'US',

    // Delivery contact information
    deliveryFirstName: "John",
    deliveryLastName: "Smith",
    deliveryPhone1: "1234567890",
    deliveryEmail1: "john.smith@kodaris.com",

    // Requested ship date; ensure it is in format: YYYY-MM-DD
    "deliveryDate": "2024-07-14",


    // Order items
    orderItems: [
        {
            code: "509382",
            quantity: 2,
            plainNote: "I really like this item, do you have it in color blue as well?"
        },
        {
            code: "345744",
            quantity: 1
        }
    ]
}

Example

// login
var loginRes = kd.http.fetch({
  method: 'POST',
  url: 'https://commerce.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://commerce.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;

var orderRes = kd.http.fetch({
  method: 'POST',
  url: 'https://commerce.kodaris.com/api/account/order',
  version: 2,
  queryParams: {completeOrder: false},
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'userSessionApiKey': userSessionApiKey,
    'X-CSRF-TOKEN': token
  },
  body: {
  "orderItems":[
    {
    "code": "hr2641",
    "quantity": 2,
    "plainNote": "I really like this item, do you have it in color blue as well?"
    }
  ],
  "organization": "Kodaris",
  "firstName": "John",
  "lastName": "Smith",
  "phone1": "1234567890",
  "email1": "john.smith@kodaris.com",
  "address1": "123 Some Address",
  "address2": "Suite 2",
  "city": "Atlanta",
  "state": "GA",
  "postalCode": "1234",
  "country": "US",
  "deliveryAddressCode": "2088_3007_j35009",
  // "deliveryOrganization": "Kodaris",
  "deliveryFirstName": "John",
  "deliveryLastName": "Smith",
  "deliveryPhone1": "1234567890",
  "deliveryEmail1": "john.smith@kodaris.com",
  // "deliveryAddress1": "123 Some Address",
  // "deliveryAddress2": "Suite 2",
  // "deliveryCity": "Atlanta",
  // "deliveryState": "GA",
  // "deliveryPostalCode": "1234",
  // "deliveryCountry": "US",
  "notes": "Please deliver the order between 9AM and 7PM",
  "purchaseOrder": "TEST"
},
});

kd.log('order result', orderRes);

-> response ->
{
  "status" : 200,
  "errors" : null,
  "body" : {
    "success" : true,
    "code" : 200,
    "messages" : null,
    "errors" : null,
    "data" : {
      "orderID" : 4082,
      "organization" : "Kodaris",
      "firstName" : "John",
      "lastName" : "Smith",
      "email1" : "john.smith@kodaris.com",
      "phone1" : "1234567890",
      "address1" : "123 Some Address",
      "address2" : "Suite 2",
      "city" : "Atlanta",
      "state" : "GA",
      "postalCode" : "1234",
      "country" : "US",
      "countryName" : "United States",
      "deliveryOrganization" : "Hill Ave.",
      "deliveryFirstName" : "John",
      "deliveryLastName" : "Smith",
      "deliveryEmail1" : "john.smith@kodaris.com",
      "deliveryPhone1" : "1234567890",
      "deliveryAddress1" : "491 Paris Hill Ave.",
      "deliveryAddress2" : "491 Paris Hill Ave.",
      "deliveryCity" : "Jenison",
      "deliveryState" : "MI",
      "deliveryPostalCode" : "49428",
      "deliveryCountry" : "US",
      "deliveryCountryName" : "United States",
      "deliveryGeneralContractor" : null,
      "displayPricing" : true,
      "completed" : null,
      "orderNumber" : null,
      "status" : "Initialized",
      "statusDetails" : null,
      "storeLogo" : "https://s3.amazonaws.com/commerce.kodaris.com/commerce.kodaris.com/content/logo_kodaris_250px.png",
      "storeName" : "Kodaris",
      "storeAddress1" : "PO Box 2256",
      "storeAddress2" : "",
      "storeCity" : "Peachtree City",
      "storeState" : null,
      "storePostalCode" : "3026",
      "storePhone" : "(555) 555-5555",
      "storeEmailAddress" : "sales@kodaris.com",
      "notes" : "Please deliver the order between 9AM and 7PM",
      "purchaseOrder" : "TEST",
      "extra5" : null,
      "formattedExtra5" : null,
      "shippingMethod" : null,
      "billingAddressCode" : "2088_3007_W0000068",
      "deliveryAddressCode" : "2088_3007_j35009",
      "trackingNumber" : null,
      "customerID" : 1386,
      "custno" : "2088",
      "invoicedt" : null,
      "shipdt" : null,
      "shipInstructions" : null,
      "shipto" : "J35009",
      "takenby" : null,
      "userName" : "elizabeth@apikey.kodaris.com",
      "slsrepout" : null,
      "slsrepin" : null,
      "orderTypeDetails" : null,
      "whse" : "SS",
      "taxablefl" : null,
      "dueDate" : null,
      "shiptoEndDate" : null,
      "shiptoStartDate" : null,
      "quoteTypeDetails" : null,
      "deliveryDate" : null,
      "reqshipdt" : null,
      "requestedPaymentAmount" : null,
      "enterdt" : null,
      "orderItems" : {
          ...
      },
      "shippingMethodName" : null,
      "parentOrderType" : null,
      "nolineitem" : null,
      "totqtyshp" : null,
      "termsTypeDescription" : null,
      "termsType" : "210",
      "termsdiscamt" : null,
      "label" : "Order",
      "isOverSpendingLimit" : false,
      "formattedExpirationDate" : null,
      "orderShipments" : { },
      "addItemsToOrderStatus" : null,
      "showPODFiles" : false,
      "extra1" : null,
      "remitName" : "Kodaris",
      "remitAddress1" : "PO Box 2256",
      "remitAddress2" : "",
      "remitCity" : "Peachtree City",
      "remitState" : null,
      "remitPostalCode" : "3026",
      "remitPhone" : "(555) 555-5555",
      "remitEmailAddress" : "sales@kodaris.com",
      "whseName" : "Seattle, WA",
      "whseAddress1" : "7999 Orchard Ave.",
      "whseAddress2" : null,
      "whseCity" : "Seattle",
      "whseState" : "Washington",
      "whseCountry" : "United States",
      "whsePostalCode" : "98101",
      "companyID" : 473,
      "companyCode" : "2088_3007",
      "companyName" : "Four Presidents",
      "termstype" : "210",
      "purchaseOrderRequired" : false,
      "formattedOrderDate" : null,
      "subtotal" : 404.1,
      "formattedSubtotal" : "$404.10",
      "discounts" : {
        "0" : {
          "name" : "Discount Amount",
          "total" : "($40.00)"
        }
      },
      "allDiscounts" : {
        "0" : {
          "name" : "Discount Amount",
          "total" : "($40.00)"
        }
      },
      "allCharges" : { },
      "formattedTotalCharge" : "($40.00)",
      "shipping" : 0,
      "extraChargeTaxable" : 0,
      "extraCharge" : 0,
      "tax" : 0,
      "total" : 364.1,
      "formattedShipping" : "$0.00",
      "formattedExtraChargeTaxable" : "$0.00",
      "formattedExtraCharge" : "$0.00",
      "formattedTax" : "$0.00",
      "formattedTotal" : "$364.10"
    },
... omitted for brevity
In this article