Bulk Upsert
This guide provides a practical example of performing bulk insert and update operations using the upsertFunctions API. The concepts and methodology outlined here can be adapted to implement similar bulk upsert actions for other APIs, enabling developers to efficiently manage large datasets while adhering to best practices.
upsertFunctions
upsertFunctions
The upsertFunctions
API call allows for bulk insertion or updates of multiple function records in a single request. This method streamlines the process by enabling developers to pass data in the body as form-data in text format. Use this call to efficiently manage function data such as function codes, active flags, and descriptions.
Request Header
Include the API key in the header to authenticate the request.
{
"Content-Type": "multipart/form-data",
"api-key": "your_api_key"
}
Form Body
The data for this API call should be passed as form-data in the following format. The key for the body should be $rows
, and the value should be a JSON array of objects, where each object represents a record to be inserted or updated.
Example Form Body
{
"$rows": [
{
"functcode": "TESTA",
"activeFlag": "Y",
"name": "A Name",
"flagType": "B",
"descr": "Test A"
},
{
"functcode": "TESTB",
"activeFlag": "Y",
"name": "B Name",
"flagType": "B",
"descr": "Test B"
},
{
"functcode": "TESTC",
"activeFlag": "Y",
"name": "C Name",
"flagType": "B",
"descr": "Test C"
}
]
}
Example Request
POST https://api.data-basics.net/apihub/apis/upsertFunctions
Explanation of the $rows
Field
$rows
FieldThe $rows
field contains an array of objects, where each object represents a record. Each record includes the following fields:
functcode
: The unique code identifying the function.activeFlag
: Indicates whether the function is active. Acceptable values areY
(active) orN
(inactive).name
: The name of the function.flagType
: The type of the function, represented as a single character (e.g.,B
).descr
: A description providing additional details about the function.
Response
The response will confirm the success or failure of the bulk insert/update operation for the provided records. It may also include a single response of inserted/updated data to show success.
Detailed examples of this process are available in our Postman examples as Bulk Upsert.postman_collection.json.
To ensure a smooth and efficient experience, we recommend adhering to the following best practices:
Recommendations for Bulk Insert/Update:
- Maximum Payload Size:
- Up to 5MB per request.
- For batch operations (insert/update), the maximum size increases to 10MB.
- Maximum Records per Batch:
- Limit each request to 100 records.
- If working with larger datasets, adjust batch sizes to avoid exceeding the payload size limit.
- Request Timeouts:
- Ensure that requests complete within 30 seconds to prevent server timeouts.
- Retry Mechanism:
- Implement error handling for timeout errors.
- If a request fails, retry with smaller batch sizes as necessary.
By following these recommendations, developers can minimize the risk of errors and optimize the performance of bulk operations.
Updated about 2 months ago