Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

NetSuite OAuth1

See more OAuth1 Examples

Demonstrates adding OAUth1 authentication to a NetSuite REST API request.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;

public class ChilkatExample {

    public static void main(String[] args) {
        // It requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        http.setOAuth1(true);
        http.setOAuthConsumerKey("CONSUMER_KEY");
        http.setOAuthConsumerSecret("CONSUMER_SECRET");
        http.setOAuthToken("ACCESS_TOKEN");
        http.setOAuthTokenSecret("TOKEN_SECRET");
        http.setOAuthRealm("ACCOUNT_ID");
        http.setOAuthSigMethod("HMAC-SHA256");

        // Not sure if this is needed for NetSuite requests.
        http.setRequestHeader("Cookie", "NS_ROUTING_VERSION=LAGGING");

        // Replace ACCOUNT_ID with your actual account id, which is likely a 7-digit decimal number.
        HttpResponse resp = new HttpResponse();
        try {
            http.httpNoBody("GET", "https://ACCOUNT_ID.suitetalk.api.netsuite.com/services/rest/record/v1/salesOrder", resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Response Status Code: " + resp.getStatusCode());
        System.out.println("Response Body:");
        System.out.println(resp.getBodyStr());
    }
}