UPDATE Endpoint(POST)
  • 29 Nov 2022
  • 4 Minutes to read
  • Dark
    Light

UPDATE Endpoint(POST)

  • Dark
    Light

Article Summary

UPDATE Endpoint(POST)

Initial Preparation

The Endpoint is accessed through the url {{baseURL }}/CSSAPI/V2/{{entityName}} /Update

  • baseURL – your company’s ContractInsight URL
  • entityName – name of the database table 

The HTTP request type is POST. Content type for this request is set to application/json. 

Introduction

UPDATE Endpoint allows you to update records in Contract Insight database. Things to keep in mind when making calls to UPDATE Endpoint:

  1. We can only perform a single table update per request. The total number of updated records cannot exceed 500.
  2. Fields that cannot be updated include fields of type GUID (uniqueidentifier), password field, out-of-the-box date fields such as DateEntered, EntryDate, DateCreated, CreatedDate.

Request format

The following format must be used in the request body when making calls to UPDATE Endpoint.

 Continued

 

  1. Tuples– a collection of column objects. Each column object has two attributes
    1. Name – table column name
    2. Value – table column value
  2. Clause – same clause we used in the GET Endpoint section. Please be aware that you can
  3. TriggerWorkflow  

Response

Standard response for both Successful and Failed responses:

  1. TotalAffected – integer representing number of rows affected
  2. TotalFailed – integer representing number of rows for which update operation failed
  3. Message – string value representing error description, otherwise has NULL value

Example of a successful response:

 

Example of a failed response:

 

More on Failed Responses

The error response described above occurred because of an exception, unhandled by REST API. Clients typically never see the exception shown above. The typical failed responses will include the message text and a LogId:

In this example, we provided wrong column name in the Name attribute of one of the tuple objects (column name). This response includes the error message.

 

Simultaneous Updates

REST API supports 500 simultaneous record updates. Please be aware that 500 simultaneous requests do NOT refer to multiple updates sent in bulk to REST API. API receives one update request at a time. What is meant here is that when you are updating by a column value that appears more than once in the table, only 500 records having this value in the target column will be updated. In other words, not more than 500 rows can be modified as a result of a single Update request sent to REST API. If we attempt to do so, we will get an error response back and the SQL transaction will be rolled back, meaning no rows will be affected.

Let’s see an example. Let’s imagine we have 800 records in our tblCustomers table that have State column set to “CA”. Let’s say we want to deactivate all customer records from California.


tblCustomers db snapshot

 



This is what we have so far. We pulled all records with the State column set to “CA”. ActiveYN fields is set to 1. (VendorName happens to be the same for all rows, but records are unique). We have 800 records where State column is set to “CA”.

 

Partial

Partial (Rules key)

Now we run our update request. We get the following error response back:

 

SQL Equivalent for this request:

UPDATE tblCustomers SET ActiveYN = 0 WHERE [State] = 'CA'

 

To sum up, if the number of records affected by the UPDATE statement exceeds 500, no records will be affected.

UPDATE Endpoint in Action (Postman Examples)

Examples below are performed on Customers table.

Task 1: Multi column update

Let’s update Vendor name and Active status to be “Some Vendor” and 1 respectively for the Vendor that has ID of 170.

Request Body

{   

    "Tuples":[

      {

         "Name":"ActiveYN",

         "Value":"true"

      }, 

      {

          "Name": "VendorName", 

          "Value": "Some Vendor"

      }

   ],

 


 

  "Clause":{

      "Condition":"AND",

      "Field":null,

      "Id":null,

      "Input":null,

      "Operator":null,

      "Rules":[

         {

            "Condition":null,

            "Field":"VendorID",

            "Id":"VendorID",

            "Input":null,

            "Operator":"equal",

            "Rules":null,

            "Type":"int",

            "Value":170

         }

      ],

      "Type":null,

      "Value":null

   },

   "TriggerWorkflow":false

}


 

SQL Equivalent

Result (Partial)

 

UPDATE tblCustomers SET VendorName = 'Some Vendor', ActiveYN = 1 WHERE VendorID = 170

 

{

    "TotalAffected": 1,

    "TotalFailed": 0,

    "Message": null

}

 


 

Task 2: Update with invalid column name

In this example, we attempt to perform the same query as in the above example, except this time, we set column name for the second tuple to “VendorNamee”. The column name doesn’t exist in the table, and we get an error.

Request Body

{   

    "Tuples":[

      {

         "Name":"ActiveYN",

         "Value":"true"

      }, 

      {

          "Name": "VendorNamee", 

          "Value": "Some Vendor"

      }

   ],

 


   "Clause":{

      "Condition":"AND",

      "Field":null,

      "Id":null,

      "Input":null,

      "Operator":null,

      "Rules":[

         {

            "Condition":null,

            "Field":"VendorID",

            "Id":"VendorID",

            "Input":null,

            "Operator":"equal",

            "Rules":null,

            "Type":"int",

            "Value":170

         }

      ],

      "Type":null,

      "Value":null

   },

   "TriggerWorkflow":false

}


 

SQL Equivalent

Result (Partial)

 

UPDATE tblCustomers SET VendorNamee = 'Some Vendor', ActiveYN = 1 WHERE VendorID = 170

 

{

    "LogId": "eef4d0f6-b25d-4ade-8214-c63ce1455e46",

    "Message": "VendorNamee does not exist.",

    "Exception": null

}


 

Task 3: Update with invalid column type

In this example we attempt to set the value for ActiveYN column to “hello world”, which causes type mismatch because ActiveYN holds values of bit type in the database. The error message we receive would indicate required data type to be “System.Boolean”. In the context of this example, bit and Boolean data types are treated to be the same.

Request Body

{   

    "Tuples":[

      {

         "Name":"ActiveYN",

         "Value":"hello world"

      }, 

      {

          "Name": "VendorName", 

          "Value": "Some Vendor"

      }

   ],


 

   

"Clause":{

      "Condition":"AND",

      "Field":null,

      "Id":null,

      "Input":null,

      "Operator":null,

      "Rules":[

         {

            "Condition":null,

            "Field":"VendorID",

            "Id":"VendorID",

            "Input":null,

            "Operator":"equal",

            "Rules":null,

            "Type":"int",

            "Value":170

         }

      ],

      "Type":null,

      "Value":null

   },

   "TriggerWorkflow":false

}

 


SQL Equivalent

Result (Partial)

 

UPDATE tblCustomers SET VendorName = 'Some Vendor', ActiveYN = 'hello world' WHERE VendorID = 170
{

    "TotalAffected": 0,

    "TotalFailed": 0,

    "Message": "Could not convert value of hello world to type of System.Boolean."

}


 

Task 4: No records found to match the criteria

In this example we run the same query as in Task 1, except for VendorID, we provide non-existing value of 1055. As a result, we get an error

Request Body

{   

    "Tuples":[

      {

         "Name":"ActiveYN",

         "Value":"true"

      }, 

      {

          "Name": "VendorName", 

          "Value": "Some Vendor"

      }

   ],


 

   

"Clause":{

      "Condition":"AND",

      "Field":null,

      "Id":null,

      "Input":null,

      "Operator":null,

      "Rules":[

         {

            "Condition":null,

            "Field":"VendorID",

            "Id":"VendorID",

            "Input":null,

            "Operator":"equal",

            "Rules":null,

            "Type":"int",

            "Value":1055

         }

      ],

      "Type":null,

      "Value":null

   },

   "TriggerWorkflow":false

}


 

SQL Equivalent

Result (Partial)

 

UPDATE tblCustomers 
SET VendorName = 'Some Vendor', ActiveYN = 1 
WHERE VendorID = 1055
{

    "TotalAffected": 0,

    "TotalFailed": 0,

    "Message": "No records found to match your criteria or table is empty."

}


 

 


Was this article helpful?