XML API Call and Response
Client applications must make an HTTP call to send a XML API request that includes a series of commands to the XML API endpoint. The XML API processes the commands in the XML API request and sends a response back to the client application.
This topic describes the HTTP Call Syntax, XML API Request Syntax, XML Data Object Syntax and XML API Response. You can also walk through an example of XML API request and response – see XML API Request and Response Sample Codes.
This guide provides formatted XML syntax and code samples with line returns and indentation throughout. Client applications typically send and receive XML content in its raw form (minified).
HTTP Call Syntax
PUT /api.pl HTTP 1.1
Host: company-id.app.netsuitesuiteprojectspro.com
Content-Type: application/xml
<!-- XML API request -->
-
HTTP method – Use either
PUTorPOST. Many libraries support either or both of these methods. From the XML API point of view, thePUTandPOSTare almost identical. -
XML API endpoint –
https://<account-domain>/api.pl -
HTTP call headers:
-
Host– The account-specific domain name for your SuiteProjects Pro account is typically sent in theHostheader. For more information about your account-specific domain name, see Your Account URLs. -
Content-Type– The XML API request in the body of the call uses XML syntax (application/xml).
-
-
HTTP Call Body – The XML API request. See XML API Request Syntax.
XML API Request Syntax
All requests sent to the XML API endpoint must use the following syntax.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<request API_version="1.0" client="example client" client_ver="1.1" namespace="example" key="Your_API_Key">
<Auth>
<Login>
<access_token>OAuth2_access_token</access_token>
</Login>
</Auth>
<!-- XML API commands -->
</request>
In the example, Your_API_Key is your API key and OAuth2_access_token is the OAuth 2.0 access token obtained for the client application connecting to SuiteProjects Pro.
Each request includes a XML prolog followed by a request element that contains the XML API commands.
-
XML prolog – SuiteProjects Pro uses UTF-8 encoding to store and display characters. Specify the encoding in the XML prolog to ensure that non-Latin characters are handled and stored correctly.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> -
Root element – The
requestelement is the root element and the immediate parent to all command elements in the XML API request.-
The
requestelement has the following attributes:Attribute
Description
API_versionThe
API_versionattribute value is always1.0clientThe name of your client application
client_verThe version number of your client application
namespaceThe API namespace assigned to your SuiteProjects Pro account. See Step 1: Enabling API Access.
keyThe API key assigned to your SuiteProjects Pro account. See Step 1: Enabling API Access.
-
All command elements are siblings and direct descendants of the
requestelement.-
The first command in the request must be the
Authcommand. Successful authentication is required for all other commands exceptTime. See also Authentication. -
Subsequent commands can be used to interact with your SuiteProjects Pro data. Depending on the operation, each command element may have a child business data object element. See the following topics for information about the type of information you can perform, and for information about the syntax and usage of each command.
-
-
The XML syntax is case sensitive. Element tags for XML API commands and objects always start with an uppercase character. Element tags for object properties always start with a lowercase character.
XML Data Object Syntax
An object element is defined by an XML start and end tag pair specifying the object type, and all the children property elements within this tags.
Each property element is defined by an XML start and end tag pair specifying the property name, and the property value within this tags.
<ObjectType>
<property_name_1>property_value_1</property_name_1>
<property_name_2>property_value_2</property_name_2>
<property_name_3>property_value_3</property_name_3>
<!-- Additional property elements -->
</ObjectType>
Elements for properties referencing related object(s) by internal ID may include the attribute external or name. You can use this to look up the internal ID of a related object using its external ID or name as foreign key. See Related Object Lookup Using the XML API.
Property elements with empty values can be represented using an XML start and end tag pair with no content (such as the property_name_1 element in the following example), or with a self-closing XML tag, if you want to set the property to an empty value (such as the property_name_2 element in the following example).
<property_name_1></property_name_1>
<property_name_2/>
Property elements can be omitted if you do not want to set a value.
Property values can either be text or an XML substructure. Properties containing address information, date or time information, and account or user settings use have an XML substructure as property value. These XML substructures use the same syntax as for XML data objects. The following example shows the XML syntax for a property including address information:
<addr>
<Address>
<first>John</first>
<last>Smith</last>
<phone>123-345-6789</phone>
</Address>
</addr>
For more information about supported business object types and their properties, see XML and SOAP API Business Object Reference.
XML API Response
The XML API response uses a syntax similar to the request sent to the XML API endpoint.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response>
<Auth status = "0"></Auth >
<!-- XML API command responses -->
</response>
Each response includes a XML prolog followed by a response element that contains the responses to each XML API command sent in the request.
-
XML prolog – SuiteProjects Pro uses UTF-8 encoding to store and display characters.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> -
Root element – The
responseelement is the root element and the immediate parent to all command response elements in the XML API response.-
The
responseelement has no attributes unless the XML request is malformed, in which case it has astatusattribute set to1.Attribute
Description
statusOnly included and has the value
1if the XML request is malformed.<response status="1">unclosed token at line 1, column 322</response> -
All command response elements are siblings and direct descendants of the
responseelement.-
Command response elements in the response follow the same sequence as the command elements in the request.
-
The names of command response elements in the response are the same as the names of the corresponding command elements in the request.
The first child element is an
Authelement returned in response to theAuthcommand in the request.Subsequent elements show the outcome of each subsequent commands in the request. Depending on the operation, each of these element may have children business data object elements. For example, if the request included a
Readcommand element and aCreateUsercommand element, the response includes aReadelement and aCreateUserelement in the same order. TheReadelement has up to 1,000 children (objects of the requested type), theCreateUserhas one child (Userobject). -
Each command response element includes a
statusattribute which indicates the success or failure of the operation. For more information about the command response status, see Error Codes.
-
-
XML API Request and Response Sample Codes
The following XML API request sample code includes the following operations:
-
Authelement – Authentication using OAuth 2.0 access token. -
Timeelement – Retrieves the time from the SuiteProjects Pro API server. -
Readelement – Retrieves up to 100 invoices from SuiteProjects Pro starting with index0. -
CreateUserelement – Add the user John Smith to the account. In this example, the value specified for the Company ID includes a typographic error.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<request API_ver="1.0" client="sample code" client_ver="1.1" namespace="example" key="Your_API_Key">
<Auth>
<Login>
<access_token>OAuth2_access_token</access_token>
</Login>
</Auth>
<Time/>
<Read type="Invoice" limit="0,100" method="all"/>
<CreateUser>
<Company>
<nickname>company_id_with_typo_error</nickname>
</Company>
<User>
<name>jsmith</name>
<password>new_user_password</password>
<taapprover>16</taapprover>
<teapprover>16</teapprover>
<addr>
<Address>
<first>John</first>
<last>Smith</last>
<phone>123-345-6789</phone>
</Address>
</addr>
</User>
</CreateUser>
</request>
In the example, Your_API_Key is your API key and OAuth2_access_token is the OAuth 2.0 access token obtained for the client application connecting to SuiteProjects Pro.
The XML API response returns:
-
Authelement – A successful authentication status. -
Timeelement – The time on the SuiteProjects Pro API server as aDateobject. -
Readelement – Up to 100Invoiceobjects. There are only 2 invoice records in the example SuiteProjects Pro account. -
CreateUserelement – An error status with error code201. A subsequent request can be sent to retrieve the error description corresponding to error code201, if required. See Error Codes.
<response>
<Auth status="0"></Auth>
<Time status="0">
<Date>
<day>13</day>
<month>02</month>
<year>2024</year>
<hour>23</hour>
<minute>59</minute>
<second>01</second>
</Date>
</Time>
<Read status="0">
<Invoice>
<id>1</id>
<number>234</number>
<customerid>204</customerid>
<total>99.00</total>
<tax>0.00</tax>
<balance>80.00<balance>
<draw>1</draw>
<credit/>
<credit_reason/>
<terms/>
<emailed>
<Date>
<day>13</day>
<month>2</month>
<year>2024</year>
<hour>0</hour>
<minute>0</minute>
<second>0</second>
</Date>
</emailed>
</Invoice>
<Invoice>
<id>4</id>
<number>983</number>
<customerid>204</customerid>
<total>12.00</total>
<tax>0.00</tax>
<balance>50.00<balance>
<draw>1</draw>
<credit/>
<credit_reason/>
<terms/>
<emailed/>
</Invoice>
</Read>
<CreateUser status="201"></CreateUser>
</response>