Collection.AddItem
  • 25 May 2021
  • 1 Minute to read
  • Contributors
  • Dark
    Light
  • PDF

Collection.AddItem

  • Dark
    Light
  • PDF

Description

Adds an item to a collection with the values specified.

It is also possible to add items in bulk by attaching XML or JSON to the request. This option should be used whenever a large number of items needs to be inserted all at once.

URL parameters

URL parameter ordering

The URL parameters below are listed in the order they should be entered in the API URL.

Name Required Type Description
CollectionID True numeric Unique identifier for the new collection.
Field.<FieldName> False string Field name and its value.

Request body (optional)

The fields and values of the rows you want to add in bulk. You can format these in XML or in JSON.

XML

Name Required Type Description
File False XML A file containing the items, fields, and values of the data to be added. POST using Content-Type multipart/form-data.
<ItemList>
	<Item>
		<Field1>Value1</Field1>
		<Field2>Value2</Field2>
	</Item>
	<Item>
		<Field1>Value3</Field1>
		<Field2>Value4</Field2>
	</Item>
</ItemList>

JSON

Name Required Type Description
POSTDATA False JSON JSON array of objects with fields and values of the data to be added. POST using Content-Type application/x-www-form-urlencoded.
[
  { "Field1": "Value1", "Field2": "Value2" },
  { "Field1": "Value3", "Field2": "Value4" }
]

Responses

Name Type Description
Result string Success if the operation was successful.
ItemID numeric Unique identifier of the new item (returned only when using the GETmethod to add a single row).

Sample requests

GET with fields and values specified in the URL

curl -X GET 'https://api.mozenda.com/rest?WebServiceKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&Service=Mozenda10&Operation=Collection.AddItem&CollectionID=1001&Field.FirstName=John&Field.LastName=Smith'

POST - XML body

curl -X POST 'https://api.mozenda.com/rest?WebServiceKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&Service=Mozenda10&Operation=Collection.AddItem&CollectionID=1001'
-F 'file=@/path/to/file.xml'

POST - JSON body

curl -X POST 'https://api.mozenda.com/rest?WebServiceKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&Service=Mozenda10&Operation=Collection.AddItem&CollectionID=1001'
-d '[{"Field1": "Value1", "Field2": "Value2"}, {"Field1":"Value11", "Field2": "Value22"}]'

Sample responses

XML

<?xmlversion="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> <!--ItemID is returned only when using the GET call  to add a single row-->
</CollectionAddItemResponse>

JSON (add &ResponseFormat=JSON)

{
  "JsonResult": {
    "Command": "Collection.AddItem",
    "AutoLoggedIn": false,
    "WebConsoleKey": "",
    "Result": "Success",
    "ErrorCode": "",
    "ErrorDescription": "",
    "ErrorList": [],
    "ExecutionTime": {
      "Ticks": 0,
      "Days": 0,
      "Hours": 0,
      "Milliseconds": 0,
      "Minutes": 0,
      "Seconds": 0,
      "TotalDays": 0,
      "TotalHours": 0,
      "TotalMilliseconds": 0,
      "TotalMinutes": 0,
      "TotalSeconds": 0
    }
  }
}

Was this article helpful?