Netsuite API Testing Script

Although I have posted many code samples on this site, I have rarely included a fully functional script. Often login information or execution code was not included since it wasn’t relevant to the particular post. However, here is a complete script that will fetch a record and then var dump it.

Although this may seem useless, its a very handy script. Before saving my own object to Netsuite, I often load one and var_dump it so that I can understand it’s structure.

Here is the code:

#!/usr/bin/php
<?php
//Values you MUST change
require_once('/your/path/here/PHP_Toolkit_v2009_2/PHPtoolkit.php');
$accountNumber = '1111111';
$roleNumber = '1';
$pass = 'yourNetsuitePassword';
$email = 'yourEmail@domain.com';
$id = 111; //must be a valid internalId

//Values you may have to change
$recordType = 'nonInventoryResaleItem';//Change if you want

//execution code
global $myNSclient;
global $myDirectory;
$myNSclient = new nsClient(nsHost::live);
$myNSclient->setPassport($email,$pass,$accountNumber,$roleNumber);
$ref = new nsRecordRef();
$ref->setFields(array(
        'internalId' => $id,
        'type' => $recordType
));
$readResponse = $myNSclient->get($ref);
var_dump($readResponse);
?>

Assuming you set the values correctly, this script should be functional. You should see a large amount of output that will either be an error report from Netsuite or the object you requested (wrapped inside a read response object). Its worth noting that this script is designed to run on Linux, so the #!/usr/bin/php would not apply to users of other operating systems.

This entry was posted in Beginning with the PHPToolkit and tagged , , , , , , . Bookmark the permalink.

One Response to Netsuite API Testing Script

  1. krishan says:

    Hi

    How to use single sign on in my application using netsuite api

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>