NetSuite to Redshift

Hi NetSuite user! This page provides you with instructions on how to extract data from NetSuite’s backend and load it into Amazon Redshift. (If this manual process is a bit more involved than you’d prefer, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

Pulling Data Out of NetSuite

Getting your NetSuite data into Amazon Redshift starts with pulling that data off of NetSuite’s servers. You can do this using the SuiteScript API, which is available to all NetSuite customers. The best documentation around for the SuiteScript API is this 1000+ page manual.

Sample NetSuite Data

The NetSuite ScriptSuite API returns JSON-formatted data. Have a look below at what responses will look like.

{  
   "salesdescription":"Cat 5 Patch Cable 10 ft",
   "vendorname":"CABL0002-64",
   "averagecost":3.50,
   “pricing”:[  
      …      {  
         "currency":{  
            "name":"British pound",
            "internalid":"2"
         },
         “pricelist”:[  
            {  
               "pricelevel":{  
                  "name":"Alternate Price 1",
                  "internalid":"2"
               },
               "price":[  
                  {  
                     "price":9.03,
                     "quantitylevel":"1",
                     "quantity":0
                  },
                  {  
                     "price":8.55,
                     "quantitylevel":"2",
                     "quantity":10
                  }
               ],
               "discount":{  
                  "name":"-5.0%",
                  "value":"-5.0%"
               }
            },
            {  
               "pricelevel":{  
                  "name":"Alternate Price 2",
                  "internalid":"3"
               },
               "price":[  
                  {  
                     "price":8.55,
                     "quantitylevel":"1",
                     "quantity":0
                  },
                  {  
                     "price":8.10,
                     "quantitylevel":"2",
                     "quantity":10
                  }
               ],
               "discount":{  
                  "name":"-10.0%",
                  "value":"-10.0%"
               }
            },
         ]
      }      Repeat for other currencies
   ],
   "productfeed":[  
      "FROOGLE",
      "SHOPPING",
      "SHOPZILLA",
      "NEXTAG",
      "YAHOO"
   ],
   "weight":"1",
   "itemid":"Cable - Cat 5, 10 ft",
   "availabletopartners":false,
   "sitecategory":[  
      {  
         "categorydescription":"Cables",
         "category":"12",
         "isdefault":false
      }
   ],
   "costingmethoddisplay":"Average",
   "offersupport":true
}

Preparing NetSuite Data for Redshift

Here’s the tricky part: you need to map the data that comes out of each NetSuite API endpoint into a schema that can be inserted into a Redshift database. This means that, for each value in the response, you need to identify a predefined data type (i.e. INTEGER, DATETIME, etc.) and build a table that can receive them. The NetSuite API documentation can give you a good sense of what fields will be provided by each endpoint, along with their corresponding data types.

Inserting NetSuite Data into Redshift

It may seem like the easiest way to add your data is to build tried-and-true INSERT statements that add data to your Redshift table row-by-row. This will be your gut reaction if you have any experience with SQL. It will work, but isn’t the most efficient way to get the job done.

Redshift actually offers some good documentation for how to best bulk insert data into new tables. The COPY command is particularly useful for this task, as it allows you to insert multiple rows without needing to build individual INSERT statements for each row.

If you cannot use COPY, it might help to use PREPARE to create a prepared INSERT statement, and then use EXECUTE as many times as required. This avoids some of the overhead of repeatedly parsing and planning INSERT.

Keeping Data Up-To-Date

So, now what? You’ve built a script that pulls data from NetSuite and loads it into Redshift, but what happens tomorrow when you have hundreds of new data points?

The key is to build your script in such a way that it can also identify incremental updates to your data. Thankfully, NetSuite’s API results include fields like “created_at” that allow you to quickly identify records that are new since your last update (or since the newest record you’ve copied into Redshift). You can set your script up as a cron job or continuous loop to keep pulling down new data as it appears.

Other Data Warehouse Options

Redshift is totally awesome, but sometimes you need to start smaller or optimize for different things. In this case, many people choose to get started with Postgres, which is an open source RDBMS that uses nearly identical SQL syntax to Redshift. If you’re interested in seeing the relevant steps for loading this data into Postgres, check out NetSuite to Postgres

Easier and Faster Alternatives

If all this sounds a bit overwhelming, don’t be alarmed. If you have all the skills necessary to go through this process, chances are building and maintaining a script like this isn’t a very high-leverage use of your time.

Thankfully, products like Stitch were built to solve this problem automatically. With just a few clicks, Stitch starts extracting your NetSuite data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Amazon Redshift data warehouse.