upsert()

Adds or updates one or more objects.

Syntax

            UpdateResult[] upsertResults = stub.upsert(attributes, objects); 

          

Usage

Use the upsert() command to add or update one or more objects. The maximum number of objects you can upsert with one single call is 1,000.

Upserts use a lookup field to determine whether it adds or updates an object:

  • If the lookup field is not matched in any existing objects, a new object is added.

  • If the lookup field is matched one time, the existing object is updated.

The default lookup field is the object internal ID. You can also use an external ID property as a foreign key and update an object without querying the object internal ID first. See Related Object Lookup Using the SOAP API.

You can set custom field values as well as standard field values when updating objects. See Reading or Setting Custom Field Values Inline.

Arguments

Name

Type

Description

attributes

Attribute[]

Array of Attribute objects. See Add, Update and Upsert Attributes.

objects

oaBase[]

Array of oaBase objects

Response

UpdateResult[] — Array of UpdateResult objects.

Sample Code — C#

            //Define a category object to create/update in OpenAir
oaCategory category = new oaCategory();
category.name = "Updated Category";
category.externalid = "555";

// Specify that the lookup is done by external_id and not by (default) internal ID
OA.Attribute attrLookup = new OA.Attribute();
attrLookup.name = "lookup";
attrLookup.value = "externalid";

// Invoke the upsert call, passing and saving the results in an UpdateResult object
UpdateResult[] results = _svc.upsert(new OA.Attribute[] { attrLookup }, new oaBase[] { category }); 

          

Sample Code — Java

            // upsert call
// Create a category object to send to the service
oaCategory category = new oaCategory();

// Set several properties
category.setName("SOAP created category 12/4");
category.setExternalid("555");

// Specify lookup attribute
Attribute lookup = new Attribute();
lookup.setName("lookup");
lookup.setValue("externalid");

// Add the account to an array of oaBase objects
oaBase[] records = new oaBase[] { category };

// Invoke the upsert call, passing.
// and saving the results in a UpdateResult object
UpdateResult[] results = stub.upsert(new Attribute[] { lookup }, records);