Collection.AddItem
August 10, 2015
Description
Adds an item to a collection with the values specified. Instead of including the single item to be added in the request it is also possible to add items in bulk by attaching a file with the request.
Required parameters
CollectionID
Optional parameters
Field.<FieldName>
Returns
The ItemID of the newly added item, or an error message stating why it could not be added.
Example request url
Example response
<?xml version="1.0" encoding="utf-8" ?> <CollectionAddItemResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Result>Success</Result> <ItemID>1098</ItemID> </CollectionAddItemResponse>
Bulk Insertion
In addition to adding items one at a time, there is a method that can be used to add items in bulk. Below is some sample C#
code that will demonstrate how this is done. This same technique can be used in many different programming languages to add multiple items to a Mozenda collection at one time.
This option should be used whenever a large number of items need to be inserted all at once.
string webServiceKey = C70E1F84-E12B-4e73-B199-2EE6D43AF44E; //Your Account WebServiceKey. string collectionID = 1001; //The ID of the destination Collection. string url = string.Format( "https://api.mozenda.com/rest?WebServiceKey={0}&Service=Mozenda10&Operation=Collection.AddItem&CollectionID={1}", webServiceKey, collectionID); string fileName = "C:\Temp\NewItems.xml"; //Path to the file containing the items to be uploaded. WebClient client = new WebClient(); byte[] responseBinary = client.UploadFile(url, fileName); string response = Encoding.UTF8.GetString(responseBinary);
The image below illustrates the format for each item in the uploaded file.