5

I want to know does Netsuite provides REST ful api? Currently i am doing integration with my application(java) with soap based web services.i have done some research but didn't get useful information.IF it does where can i found api?

RvN
  • 133
  • 2
  • 5
  • 15

6 Answers6

10

Avoid the SuiteTalk SOAP web services API like the plague; it will do nothing but waste your time to. Usage of Netsuite SOAP API is viable only when you are okay with the SOAP API being non performant, don't mind interacting with gross buggy SOAP API, have much time to implement robust error handling to account for the random SOAP errors, concurrency errors. You'll need much time to develop robust fault tolerance. All that time will be wasted time; because no amount of time will make the SOAP API performance acceptable.

RESTlet's are preferred over SOAP API usage for writing data; RESTlets tend to be slightly more performant for writes (although responses are still extremely slow and not suitable for a customer facing app).

RESTlet's are a viable short term solution for writing data to Netsuite. Its essentially a JS script that allows you to set up a token based auth poor man's JSON endpoint; in which you can send JSON request bodies and get back JSON response bodies. Usage is reasonable in cases in which not much data needs to be written via the Restlet's (for instance for SalesOrders). A queue based system and background jobs with retry capabilities will mitigate the random Netsuite error issues (concurrency errors, timeouts etc).

If you must write to a bunch of Netsuite entities frequently and are using Netsuite as the source of truth for your data rather than attempting to build an entire REST like JSON API on top of Netsuite; I'd recommend implementing a pub/sub service in which Netsuite publishes events to an external service subscribed to by your app/API. Your app could also publish mutations to a channel subscribed to by Netsuite. This way data mutations sent to Netsuite can occur in a middle layer with reduced complexity.

To fetch Netsuite data for outside apps the most efficient means available appears to be the Netsuite ODBC database driver; it provides a direct connection to Netsuite database read only table views. Simple select queries for a set of Items that with same schema in Postgres or MySQL typically take 0.5 ms or less; typically take between 15 seconds to slightly over 100 seconds to return.

Connection timeouts and other errors from Netsuite are still common using NS ODBC driver. Despite slow query results retrieval of all data needed for a set of 5000 items in 14 seconds is far better than the hours it would take to get the same via Netsuite's SOAP API.

alex1sz
  • 340
  • 4
  • 10
7

Yes. That is in Customization/Scripts section. You will find "RestLet" there. Doc is here.

However you said your application is soap based, I suggest you take a look Netsuite's WebServices aka SuiteTalk.

The SuiteTalk Platform provides programmatic access to your NetSuite data and business processes through an XML-based application programming interface (API).

I think you do need to access to your Netsuite data, right?

You can download their sample for test and learning.

Hausen Zheng
  • 204
  • 1
  • 7
  • 3
    Just as a precaution, there are a few pros and cons to each RESTful and SOAP implementations. The main two being speed and concurrent connections. REST is fast and allows many concurrent connections, but requires more development (in my experience) to set up. SOAP is easier to configure and use, but only allows 1 connection per Netsuite account (you use your login credentials as authentication) and is relatively slow. Just my 2 cents. – tatorface Oct 10 '14 at 14:09
4

In NetSuite, you can build RESTlet scripts which provide a REST-based interface. You can essentially use them to build your own JSON API. Recommend researching RESTlets in the NetSuite Help.

erictgrubaugh
  • 8,519
  • 1
  • 20
  • 28
  • 1
    As of NetSuite 2019.2, SuiteTalk now offers a RESTful JSON API in addition to the previous SOAP API. The REST API is currently in Beta status. You can find the details here: https://docs.oracle.com/cloud/latest/netsuitecs_gs/NSTRW/NSTRW.pdf – erictgrubaugh Nov 29 '19 at 21:20
  • 1
    Keep in mind that all problems mentioned above by @alex1sz are true for REST APIs as well. The REST API follows HATEOS, which makes it extraordinarily less performant due to link traversals everywhere. Connection timeouts are rampant with REST. APIs for fetching lists are missing. Enumerations only return internalIds and not labels in metadata-catalog APIs. Labels for sublists and reference fields are missing as well. Too much use of nsObject (equivalent to RecordRef in SOAP), even when the types are well-defined (company on oppty is always customer, but the type is nsObject for some reason) – Neelesh Mar 30 '20 at 18:00
  • 1
    @Neelesh Im confused how such big companies deliver solutions that are so obviously lacking. Why they went with SOAP in the first place is just horrifying to even think of. Will using restlets to provide api also suffer from similar issues? Or you just referring specifically to the rest api from netsuite? – West Jun 21 '20 at 02:56
  • @West, per NetSuite, "RESTlets are the fastest integration channel. All actions required for a business flow can be executed within a single call." And from another NetSuite document: "You can create a RESTlet so that all actions required for a business flow can be executed within a single call. RESTlets can be tailored for a specific need and are highly efficient." – Jonathan Hult Aug 10 '20 at 23:28
  • @Neelesh Great thanks for clarifying – West Aug 10 '20 at 23:32
4

SOAP is easier to configure and use, but only allows 1 connection per Netsuite account (you use your login credentials as authentication) and is relatively slow.

That's not quite true, as you can extend it with suite cloud plus program. Check help for: - Understanding Web Services Governance - Enabling Web Services Concurrent Users with SuiteCloud Plus

UPDATE: There are two types of governance in NetSuite since approx July 2016 - user governance (also known as a legacy governance model, implicitly used when sessions / SOAP Login method are utilized) and account governance. In the account governance there is a shared pool for all incoming concurrent requests (no sessions should be used, authentication via user credentials or Token-Based Authentication).

Kikoz
  • 146
  • 4
  • 1
    Apparently, because this answer requires correction due to a new governance model. – Kikoz Jul 22 '19 at 03:32
  • This was probably downvoted because it does not answer the question. It's a reply to a comment on a different answer. – Emile Pels Sep 20 '19 at 11:45
4

This is the proper REST API provided by NetSuite for integration purposes.

https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2020.1/index.html

The REST API can be invoked either via Token-based authentication or OAuth 2.0 enabled HTTP client. First you need to login to NetSuite account and enable the SuiteTalk Webservice features of the account (Setup->Company->Enable Features). Then obtain the SuiteTalk Base URL, which contains the account ID under the company URLs (Setup->Company->Company Information). E.g., https://<ACCOUNT_ID>.suitetalk.api.netsuite.com After that create an integration application (Setup->Integration->New), enable OAuth 2.0 or TBA. This blog contains the process of enabling features and obtaining tokens.

Then use the BaseUrl + API resource path to as the HTTP client path to invoke each record API. Operations such as CRUD, search and filter can be done via this REST API. For more information See NetSuite Documentation

Chamil E
  • 478
  • 3
  • 10
1

Yes, Netsuite supports REST web services. Here's a working Java example, that uses the open source scribe library.

Note that an Accept (and for Posts, a Content-Type) header of application/json is needed for Netsuite to accept the requests, otherwise you'll get a "Request media type is not valid." error. Also getSignatureType method must be implemented for API class (NetSuiteApi.java).

Change all the string constants to suit your setup. Note that this code will also work with Netsuite RESTlets.

REST documentation is available here: https://[your-netsuite-ID].app.netsuite.com/help/helpcenter/en_US/PDF/REST_Web_Services.pdf

File #1: NetSuiteApi.java

package com.scribe.api;

import com.github.scribejava.core.builder.api.DefaultApi10a;
import com.github.scribejava.core.model.OAuth1RequestToken;

public class NetSuiteApi extends DefaultApi10a {

    private static class InstanceHolder {
        private static final NetSuiteApi INSTANCE = new NetSuiteApi();
    }

    public static NetSuiteApi instance() {
        return InstanceHolder.INSTANCE;
    }

    @Override
    public String getAccessTokenEndpoint() {
        return null;
    }

    @Override
    public String getRequestTokenEndpoint() {
        return null;
    }

    @Override
    public String getAuthorizationUrl(OAuth1RequestToken requestToken) {
        return null;
    }

    @Override
    protected String getAuthorizationBaseUrl() {
        return null;
    }

@Override
public OAuth1SignatureType getSignatureType() {
    return OAuth1SignatureType.HEADER;
}

}

File #2: NetSuiteApiCallExample.java

package com.scribe.api;

import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.model.OAuth1AccessToken;
import com.github.scribejava.core.model.OAuthRequest;
import com.github.scribejava.core.model.Response;
import com.github.scribejava.core.model.Verb;
import com.github.scribejava.core.oauth.OAuth10aService;

public final class NetSuiteRestExample {

    private String CONSUMER_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    private String CONSUMER_SECRET = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
    private String TOKEN_ID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    private String TOKEN_SECRET = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
    private String REST_URL = "https://1234567-sb1.suitetalk.api.netsuite.com/rest/platform/v1/record/inventoryitem/";
    private String REALM = "1234567_SB1";
    private String POSTBODY = "{\"type\": \"SIMPLE\",\"authorId\": -5}";

    public static void main(String[] args) {
        
        final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY).apiSecret(CONSUMER_SECRET))
                .build(NetSuiteApi.instance());
        OAuth1AccessToken accessToken = new OAuth1AccessToken(TOKEN_ID, TOKEN_SECRET);
        
        //  This is POST method call 
//      OAuthRequest request = new OAuthRequest(Verb.POST, REST_URL);
//      request.addHeader("Content-Type", "application/json");
//      // Without next line, you'll get a "Request media type is not valid." error, even though this is not needed with Postman
//      request.addHeader("Accept", "application/json");
//      request.setRealm(REALM);
//      request.setPayload(POSTBODY);

        //  This is GET method call 
        OAuthRequest request = new OAuthRequest(Verb.GET, params.get("REST_URL"));      
        // Without next line, you'll get a "Request media type is not valid." error, even though this is not needed with Postman
        request.addHeader("Accept", "application/json");        
        request.setRealm(params.get("REALM"));      
        
        
        service.signRequest(accessToken, request);
        
        System.out.println("Sending this request...");
        System.out.println(request.getHeaders());
        System.out.println(request.getCompleteUrl());
        // System.out.println(request.getPayload());
                
        final Response response = service.execute(request);

        System.out.println("Got this response...");
        System.out.println(response.getCode() + "\n" + response.getHeaders());
        System.out.println(response.getBody());
                
        return response.getBody();
    }
}

Add this to you Maven dependencies (pom.xml):

...
 <dependencies>
        ...

        <dependency>
            <groupId>com.github.scribejava</groupId>
            <artifactId>scribejava-apis</artifactId>
            <version>6.9.0</version>
        </dependency> 

 </dependencies>
Silas Palmer
  • 2,687
  • 1
  • 29
  • 30