Use this API to populate an existing dataset with new data. This API allows you to insert or append rows of data into a pre-defined dataset, making it useful for updating client data during onboarding or other data integration tasks.
For example, use this endpoint to fill a dataset with transactional data, customer information, or any other structured data relevant to your client's needs.
Fill a Dataset
To populate a dataset, follow these steps:
Make a POST request to /dataset-fill with the required parameters in the request body.
Include the user-code and dataset-code to identify the dataset and the user making the request.
Define the structure of the data by specifying the columns parameter, which includes details like column names, aliases, types, subtypes, and optional formats.
Provide the data to be inserted via the insert-data parameter.
If compressed is false, the data should be formatted as a JSON-escaped string.
If compressed is true, the data should be base64-encoded after being gzipped.
Example of insert-data with JSON (when compressed: false):
Optionally, use the append parameter to indicate whether to append the data to the existing dataset (true) or truncate the dataset before inserting the new data (false).
Optionally, use the compressed parameter to specify if the data is gzip compressed (true) or not (false).
Example Usage
Filling a Dataset with Base64-encoded Data
For example, making a POST request to the following URL with the provided JSON body would result in the response below:
The response will confirm the status of the operation, including the dataset code and the number of rows inserted.
Sample Python Code: Convert CSV Data to a Base64 Encoded String
This Python script reads data from a CSV file, converts it to JSON, compresses it using gzip, and encodes it as a Base64 string, ready to be sent via API requests.
import csvimport jsonimport gzipimport base64# Read data from CSV filedefread_csv(file_path): rows = []withopen(file_path, newline='')as csvfile: reader = csv.reader(csvfile)# Skip the header rownext(reader, None)for row in reader: rows.append(row)return rows# Convert data to JSON, compress using gzip, and encode to base64defprepare_data_for_request(data):# Encode data to JSON json_encoded = json.dumps(data)# Compress JSON data using gzip gzipped_insert_data = gzip.compress(json_encoded.encode('utf-8'))# Encode gzipped data to base64 base64_encoded_insert_data = base64.b64encode(gzipped_insert_data).decode('utf-8')return base64_encoded_insert_data# Write base64 encoded data to a filedefwrite_encoded_data_to_file(encoded_data,file_path):withopen(file_path, 'w')as file: file.write(encoded_data)print(f"Base64 encoded data has been written to {file_path}")# Main functiondefmain(): csv_file_path ='data.csv'# Replace with your CSV file path data =read_csv(csv_file_path) base64_encoded_data =prepare_data_for_request(data)# Write base64 encoded data to a file encoded_data_file ='encoded_data.txt'# Replace with your desired file pathwrite_encoded_data_to_file(base64_encoded_data, encoded_data_file)if__name__=='__main__':main()
Use the encoded string saved in the file for your JSON request.