How Can I Use the Simplified Transaction Import Rest API?

How Can I Use the Simplified Transaction Import Rest API?


This article is about the simplified transaction import REST API. Click here for more options.

Importing Sales Transactions
To import transaction data, follow these 2 steps:
  • Step 1 - Get your API key
  • Step 2 - Import transactions by making a POST call for each transaction

Step 1 - Get Your API Key
To obtain your API key:
  • Login to your workspace
  • On the left pane, click on "My Account > My Profile"
  • Click on the "Security" tab (if needed)
  • Copy the API key

Step 2 - Import Transactions
To import transactions:
  • Prepare a POST call to https://salescookie.com/app/Api/CreateTransaction
  • Set HTTP header X-ApiKey to your API key
  • Submit CSV data as POST content, such as:
  • {
      "date":"2019-07-04T02:47:42.1442597Z",
      "uniqueId":"id-123",
      "revenue":1.3,
      "profit":-2.5,
      "currency":"USD",
      "transactionStatus":"closed won",
      "customer":"Candy By Mail",
      "product":"Lemon Cake",
      "owner1":"John Doe",
      "owner2":"Jane Doe",
      "owner3":"Bob Smith",
      "team1":"USA",
      "team2":"Washington",
      "team3":"98004",
      "quantity":3,
      "costPerUnit":3.14,
      "taxes":6.54,
      "otherText1":"additional data",
      "otherText2":"more data",
      "otherText3":"even more data",
      "otherNumeric1":123.45,
      "otherNumeric2":54.321,
      "otherNumeric3":-98.76,
      "otherDate1":"2019-01-03T06:03:01Z",
      "otherDate2":"2019-05-10T08:05:09Z",
      "otherDate3":"2019-09-04T12:17:33Z"

Sample Code
The following samples show how to make calls (using C#) for a given API key, adding a transaction.

// Add a transaction
 dynamic expando = new ExpandoObject(); 
 expando.date = DateTime.UtcNow; 
 expando.uniqueId = "id-123"; 
 expando.revenue = 3.5; 
 expando.currency = "USD"; 
 expando.transactionStatus = "Closed Won"; 
 expando.customer = "Candy By Mail"; 
 expando.product = "Lemon Cake"; 
 expando.owner1 = "John Doe"; 
 expando.team1 = "Oregon"; 
 expando.quantity = 3; 
 expando.costPerUnit = 1.21; 
 expando.taxes = 0.14; 
 expando.otherText1 = "hello"; 
 expando.otherNumeric1 = 123.45; 
 expando.otherDate1 = DateTime.UtcNow; 
 string json = JsonConvert.SerializeObject(expando); 
 string url = "https://salescookie.com/app/Api/CreateTransaction";
 WebClient webClient = new WebClient(); 
 webClient.Headers.Add("X-ApiKey", apiKey); 
 string result = webClient.UploadString(url, json); 

Updating Transactions
Step 2 is typically used to create transactions. However, you can also use step 2 to update existing transactions (i.e. transactions you previously imported).

To update transactions however, each transaction must have a unique ID. Therefore, make sure you always set the "uniqueId" property in transactions you create.

That's it - the system will handle your import as a create or update depending on whether it can find a matching unique ID.