Step 1: Access NetSuite Account
- Log in to your NetSuite account.
- Navigate to Setup > Integration > Web Services Preferences.
- Here you’ll find your Account ID, which is needed for both SOAP and REST API calls.
Step 2: Create an Integration Record
- Go to Setup > Integration > New Integration.
- Fill out the details. This will give you a Consumer Key and a Consumer Secret. Keep these safe, as you’ll need them for REST API calls.
Step 3: Create a Role and User for API Access
- Create a new role by going to Setup > Users/Roles > Manage Roles > New.
- Assign this role the permissions required to access the API.
- Create a new user and assign this role tfao that user.
Step 4: Generate Token for REST API (Skip if Using SOAP)
- Navigate to Setup > Users/Roles > Access Tokens > New.
- Choose the application, user, and role you’ve set up.
- This will generate a Token ID and Token Secret. Keep these safe.
Step 5: Set Up Your PHP Environment
composer require netsuite/netsuite-php
composer require guzzlehttp/guzzle
Write Your PHP Code
Here’s a sample to get you started:
require 'vendor/autoload.php'; use NetSuite\NetSuiteService; $config = array( "endpoint" => "XXXX", "host" => "XXXX", "email" => "XXXX", "password" => "XXXX", "role" => "XXXX", "account" => "XXXX" ); $service = new NetSuiteService($config);
require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client([ 'base_uri' => 'https://XXXX.suitetalk.api.netsuite.com/', 'headers' => [ 'Authorization' => 'OAuth realm="XXXX",oauth_consumer_key="XXXX",oauth_token="XXXX",oauth_signature_method="XXXX",oauth_timestamp="XXXX",oauth_nonce="XXXX",oauth_version="1.0",oauth_signature="XXXX"' ] ]); $response = $client->get('record/v1/invoice/XXXX');