- 29 Nov 2022
- 4 Minutes to read
-
Print
-
DarkLight
UPDATE Endpoint(POST)
- Updated on 29 Nov 2022
- 4 Minutes to read
-
Print
-
DarkLight
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:
- We can only perform a single table update per request. The total number of updated records cannot exceed 500.
- 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 |
- Tuples– a collection of column objects. Each column object has two attributes
- Name – table column name
- Value – table column value
- Clause – same clause we used in the GET Endpoint section. Please be aware that you can
- TriggerWorkflow
Response
Standard response for both Successful and Failed responses:
- TotalAffected – integer representing number of rows affected
- TotalFailed – integer representing number of rows for which update operation failed
- 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.
| 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:
|
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 | |
|
|
SQL Equivalent | Result (Partial) |
|
|
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 | |
|
|
SQL Equivalent | Result (Partial) |
|
|
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 | |
|
|
SQL Equivalent | Result (Partial) |
|
|
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 | |
|
|
SQL Equivalent | Result (Partial) |
|
|