Sorry it's been a while since I've posted - but I'm working on a posting calendar, and hope to be much more regular in my posting.
I spent quite a bit of time recently, working on trying to get data to and from NetSuite using Python. There was so little information out there, so I decided it was worth outlining what I'd learned.
First, NetSuite is an enterprise SaaS EPR/CRM and accounting package. It has some traction in the nonprofit sector, which is why I have been exposed to it. I'll also say that if you get a whiff of annoyance from this post, it's because most of my experience addressing enterprise APIs is with Salesforce, and in comparison, well... let's just say NetSuite can't come close to matching the ease of Saleforce in this regard.
There are three ways to get information from NetSuite:
- SOAP API
- What they call 'RESTlets'
There are only two ways to get information into NetSuite:
I'm going to talk the least about RESTlets, because I don't have a lot of experience with them.
First off, if you are diving into the world of trying to with NetSuite using Python:
- The NetSuite API documentation is only accesible when logged into NetSuite. (PET PEEVE!)
- It's not very good.
- Examples of doing many things using Python are few and far between.
- If you have Java or C# resources at hand use those - you'll probably get further.
- The community options for getting help are rather thin.
Let's just briefly cover ODBC - it's fairly straightforward to get data from NetSuite via ODBC. If you log into your NetSuite instance, navigate to the docs, and look up ODBC connections, they include drivers for your instance. You can use pyodbc, which is a very well-maintained package to grab data from NetSuite objects. If you are doing read-only, it's probably the best option.
Python has a solid SOAP library called Zeep, and is the only one currently maintained (Suds and PySimpleSOAP have not been updated in quite a while now.) SOAP is kinda arcane, and I should have a whole blog post on how to work with SOAP.
Unlike with Salesforce, there isn't an official Python SDK for NetSuite. (The only offical SDK is in PHP and NetSuite does have example code in Java and C#.) There are two python packages, python-netsuite and netsuite. Python-netsuite hasn't been updated since 2016, netsuite is fairly recently updated. Neither worked for me - they clearly were set up for the particular use cases that these folks needed to solve, neither of which were mine. Python-netsuite has a BSD 3-Clause license, and netsuite has a strange non-license license.
I started from scratch, using NetSuite documentation, using some guidance from those packages, translation from other languages, and lots and lots of trial and error. The first biggest hurdle was figuring out namespaces. The best thing to do, first off, is to run this command (after you've installed zeep in your virtual environment):
python -mzeep (current URL for WDSL) > NetSuiteWSDL.txt
And use that as a reference for how to find out the correct namespace for whatever you are looking for.
A few important tips:
- Unlike Salesforce, you can't get records using a query language like SOQL. You have to use a search strategy, which is, IMHO less effective and more painful to code.
- There isn't a straighforward way to get all records of a table. You need to do a search, use a null as the search value, then retrieve the results page by page.
- Getting single records or writing single records is fairly straightforward.
- Zeep does a pretty good job, and getting to know some of Zeeps helpers will make your life easier.
- Custom fields are buried inside one of the columns of the result you'll get, so if you want to get the value of custom fields, you'll need to further process the results.
- If you want to search by custom fields, thats going to be a very heavy lift - it's better to grab everything, and then let python filter the results, instead of searching on values for a custom field.
I might at some point put a NetSuite toolkit up on GitHub.
All in all, I would say that if you have to get data to and from NetSuite using Python, it's doable, but not easy.