Using the WorkXpress API: AddItem
Earlier I introduced you to the WorkXpress API. If you have not read it already you should do so before reading this post. Once you have a basic understanding of what it is and how it works, it's time to start diving into the API.
This post will cover how to add Items to a WorkXpress application using the AddItem API function. AddItem allows you to set Fields and create Relationships while adding the new Item. Like the LookupData function, you can make many AddItem requests in one call using data sets.
Request XML
First, let's get an understanding of how the request XML should be formed.
| Element | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| /wxRequest | The root node for all request documents. | ||||||||||||||||||
| /wxRequest/dataSet |
Contains a single AddItem request. You may have as many data sets as you would like. Attributes:
|
||||||||||||||||||
| /wxRequest/dataSet/ item |
Used to specify the item type id of the new item. Attributes:
|
||||||||||||||||||
| /wxRequest/dataSet/fields | Root node for the fields that should be set on the new item. | ||||||||||||||||||
| /wxRequest/dataSet/ fields/field |
A single field to be set on the new item. Attributes:
|
||||||||||||||||||
| /wxRequest/dataSet/ fields/field/ value |
Value to set into the field. | ||||||||||||||||||
| /wxRequest/dataSet/ relations |
Root node for relations that should be created along with the new item. | ||||||||||||||||||
| /wxRequest/dataSet/ relations/relation |
Defines a relation to be created. Attributes:
|
||||||||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields |
Root node for the fields that should be set on the new relation. | ||||||||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields/field |
A single field to be set on the new relation. Attributes:
|
||||||||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields/field/ value |
Value to set into the field. |
Response XML
Now let's get an understanding of how the response XML will be formed.
| Element | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| /wxResponse | The root node for all response documents. | |||||||||
| /wxRequest/callStatus |
The status of the SOAP call as it was processed by WorkXpress. Attributes:
|
|||||||||
| /wxResponse/compatibilityLevel | The version of the API that was used to process the request. | |||||||||
| /wxRequest/dataSet |
One data set is returned for each data set in the request document. Attributes:
|
|||||||||
| /wxRequest/dataSet/ item |
Defines the item that was added to the WorkXpress application. Attributes:
|
|||||||||
| /wxRequest/dataSet/ item/relation |
Defines a relation that was added to the WorkXpress application. Attributes:
|
Examples
Below is an example of a basic AddItem request document:
<dataSet reference=”workxpress”>
<item itemTypeId=”a35234” />
<fields>
<field fieldId=”a66969”>
<value>WorkXpress</value>
</field>
<field fieldId=”a36314”>
<value>http://www.workxpress.com</value>
</field>
</fields>
<relations>
<relation action=”add” oppositeItemId=”u7436”
reference=”account_to_contact”
relationType=”a36495” startingSide=”base”>
<fields>
<field fieldId=”a36498”>
<value>Developer</value>
</field>
</fields>
</relation>
</relations>
</dataSet>
</wxRequest>
Below is the corresponding response document for the above example:
<callStatus status=”success” />
<compatibilityLevel>1</compatibilityLevel>
<dataSet reference=”workxpress”>
<item itemId=”u7563” itemTypeId=”a35234”>
<relation reference=”account_to_contact” relationId=”u7564”/>
</item>
</dataSet>
</wxRequest>
If you have any questions or would like assistance making some AddItem requests of your own, please feel free to comment below. My next post will be on how to use the UpdateItem request.


