Batcher and CSV parser utilities
Learn how to batch API calls and parse CSV files with Optimizely Connect Platform (OCP) utilities.
Optimizely Connect Platform (OCP) has utilities to help you batch API calls and parse CSV files.
Batcher
Batcher makes it easy to batch API calls that support arrays of records or call structures. See SDK Docs.
Sample Batcher
import { z } from '@zaius/node-sdk';
import {Transformer} from './Transformer';
import { logger, Batcher } from '@zaius/app-sdk';
import {Contact} from '../lib/Vendor';
export class ContactTransformer implements Transformer<Contact> {
private customerBatch = new Batcher(z.customer);
public async transform(contact: BrontoContact): Promise<boolean> {
await this.customerBatch.append(this.transformContactToCustomer(contact));
return false;
}
public async flush() {
try {
await this.customerBatch.flush();
} catch (e) {
logger.error('Error in sending to Zaius:', e);
}
}
private async transformContactToCustomer(contact: Contact): CustomerPayload {
return {
identifiers: {
email: contact.email,
vendor_id: contact.id,
phone: contact.mobileNumber
},
attributes: {
// customer attributes to map
}
};
}
CSV parser
Use OCP's CsvStream SDK to parse CSV files.
Updated about 1 month ago