4

Using Python, I would like to pull data from NetSuite, along with adding/updating data in NetSuite. For example, I would like to create sales orders and add line items via Python.

I'm aware that they have a WSDL that I could potentially use. (And I was hoping that they would also have an API, but apparently not...) Does anyone have examples working with this WSDL in Python? Are there better ways to integrate with NetSuite?

jonsustar
  • 203
  • 4
  • 9

3 Answers3

3

I have deal with Netsuite Webservice for around one week, there is not clear documentation but once you are align with the other regular webservices behaivour is very simple adapt yourself. I attach one little script to login and to get the full list of services and data types in netsuite.

Use the factory method to create the objects to interact with the netsuite webservice.

I have used suds as SOAP Python Library.

# -*- coding: utf-8 -*-        
from suds.client import Client
import os, time, sys, datetime
import suds
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

reload(sys)  
sys.setdefaultencoding('utf8')

NS_HOST = 'https://webservices.netsuite.com'
email ='myemail@xxxxxx.com'
pwd   ='mypwd'
account = "99999999"
NS_ENDPOINT = "2016_2"
NS_ROLE = 3

wsdl = NS_HOST + "/wsdl/v" + NS_ENDPOINT + "_0/netsuite.wsdl"

client = Client(url=wsdl)
#You can get the methods and types with this object
print client
ApplicationInfo = client.factory.create('ns16:ApplicationInfo')
ApplicationInfo.applicationId = "xxxxx-XXXX-XXXX-XXXX-XXXXXXXX"

client.set_options(location= NS_HOST + "/services/NetSuitePort_" + NS_ENDPOINT, soapheaders={'applicationInfo':ApplicationInfo})

passport = client.factory.create('ns4:Passport')
passport.email = email
passport.password = pwd
passport.account = account
recordRef = client.factory.create('ns4:RecordRef')
recordRef.name="MX - Gerencia de Contabilidad"
passport.role = recordRef

client.service.login(passport)
Nathan Villaescusa
  • 17,331
  • 4
  • 53
  • 56
1

Netsuite has provided toolkits for Java, .Net and PHP to access their webservices. For other languages either there are third party toolkits or you have to send Raw SOAP requests.

For my Python based projects I'm using Raw SOAP requests method. I suggest that first you get familiar with Netsuite Web services using any of the available toolkits and then for Python use this knowledge to generate raw SOAP requests. SOAPUI can also be of great help.

Have you explored restlets they are a generally good alternate for webservices.

Saqib
  • 2,470
  • 3
  • 19
  • 32
1

There are a number of Python libraries available for processing SOAP messages, tried using SUDS, as it is the only one capable of properly consuming the 2014.1 Netsuite WSDL. This was only possible after some tweaks. The Netsuite WSDL is large and complex and took an enormous amount of time to load, even after caching AND loading from local. The SUDS library has not been maintained for quite a while, there is a maintained fork called SUDS-jurko that I have not yet tried. Ultimately, I ended up using raw soap messages to communicate with the Netsuite webservice for specific tasks.

Community
  • 1
  • 1
smontify
  • 11
  • 1