Collection.AddUpdate
  • 14 May 2024
  • 1 Minute to read
  • Contributors
  • Dark
    Light
  • PDF

Collection.AddUpdate

  • Dark
    Light
  • PDF

Article summary

Description

Adds a new collection or updates an existing collection of the same name with the fields and data items provided. Accepts same data formats as Collection.AddItem bulk insertion. Your app should make a POST request to the request URL, passing the JSON or XML file as part of a standard form-encoded post body.

URL parameters

NameRequiredTypeDescription
NameTruestringName of the new or updated collection.

Request body

Accepts same data formats as Collection.AddItem bulk insertion. The fields and values of the rows you want to add in bulk. You can format these in XML or in JSON.

XML

NameRequiredTypeDescription
FileTrueXMLA 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

NameRequiredTypeDescription
POSTDATATrueJSONJSON 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

NameTypeDescription
ResultstringSuccess if the operation was successful.
CollectionIDnumericUnique identifier for the new or updated collection.
CollectionNamestringName for the new or updated collection.
CollectionAddedbooleanWhether or not a new collection was added.
FieldsAddednumericTotal fields added.
ItemsAddednumericTotal items added.

Sample requests

XML

curl -X POST "https://api.mozenda.com/rest?WebServiceKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&Service=Mozenda10&Operation=Collection.AddUpdate&Name=MyUpdatedCollection" \ 
-F "file=@/path/to/file.xml"

JSON

curl -X POST "https://api.mozenda.com/rest?WebServiceKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&Service=Mozenda10&Operation=Collection.AddUpdate&Name=MyUpdatedCollection" \ 
-d '[{"Field1": 1, "Field2": 2}, {"Field1": 3, "Field2": 4}]'

Sample responses

XML

<?xml version="1.0" encoding="utf-8" ?>
<CollectionAddUpdateResponse
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<Result>Success</Result>
	<CollectionID>1201</CollectionID>
	<CollectionName>AddUpdateCollectionJSON</CollectionName>
	<CollectionAdded>True</CollectionAdded>
	<FieldsAdded>3</FieldsAdded>
	<ItemsAdded>8</ItemsAdded>
</CollectionAddUpdateResponse>

JSON (add &ResponseFormat=JSON)

{
  "CollectionID": 5356,
  "CollectionName": "testapi",
  "CollectionAdded": false,
  "FieldsAdded": 0,
  "ItemsAdded": 2,
  "JsonResult": {
    "Command": "Collection.AddUpdate",
    "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?