This AWS Lambda function processes events to retrieve Zuora account data and bulk upload it to Eloqua, handling errors and returning appropriate responses. It requires additional development to implement features for import template creation and single record updates.
npm run import -- "notify entry point"
var importer = require('../Core');
var zuoraExport = importer.import("zuora account service");
var eloquaUpload = importer.import("bulk upload eloqua");
function handler(event, context, callback) {
const zuoraConfig = {
"rest_api_user": process.env.ZUORA_API_USER,
"rest_api_password": process.env.ZUORA_API_PASS,
"rest_api_url": process.env.ZUORA_API_URL
};
const eloquaConfig = {
"authorize_uri": process.env.ELOQUA_AUTHORIZE_URL,
"token_uri": process.env.ELOQUA_TOKEN_URL,
"rest_api_url": process.env.ELOQUA_API_URL,
"rest_client_id": process.env.ELOQUA_CLIENT_ID,
"rest_secret": process.env.ELOQUA_CLIENT_SECRET,
"rest_api_company": process.env.ELOQUA_API_COMPANY,
"rest_api_user": process.env.ELOQUA_API_USER,
"rest_api_password": process.env.ELOQUA_API_PASS
};
var body = event || {};
try {
if (event.body || event.queryStringParameters) {
body = Object.assign(event.body || {}, event.queryStringParameters || {});
}
} catch(e) {
console.log(e);
callback(e, {
'statusCode': 500,
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
'body': JSON.stringify({'Error': e.message})
})
return;
}
// TODO: add if statement for creating the import template
// TODO: add an entry point for Zuora subscription callout to update single records in eloqua?
return zuoraExport.getZuoraAccounts(body, zuoraConfig)
.then(accounts => eloquaUpload.bulkUploadEloqua(accounts, eloquaConfig, body.instanceId, body.executionId))
.then(() => callback(null, {
'statusCode': 200,
'headers': { 'Content-Type': 'text/plain' },
'body': 'Success!'
}))
.catch(e => callback(e.message || e.body || e, {
'statusCode': 500,
'headers': { 'Content-Type': 'text/plain' },
'body': 'Error: ' + e.message
}))
}
module.exports = {
handler
};
const { Importer } = require('../Core');
const { ZuoraAccountService } = Importer.import('zuora account service');
const { BulkUploadEloqua } = Importer.import('bulk upload eloqua');
/**
* AWS Lambda function handler.
*
* @param {Object} event - Event object containing request data.
* @param {Object} context - Context object containing AWS Lambda context.
* @param {Function} callback - Callback function to be executed after processing.
*/
function handler(event, context, callback) {
try {
// Load environment variables for Zuora and Eloqua configurations
const {
ZUORA_API_USER,
ZUORA_API_PASSWORD,
ZUORA_API_URL,
ELOQUA_AUTHORIZE_URL,
ELOQUA_TOKEN_URL,
ELOQUA_API_URL,
ELOQUA_CLIENT_ID,
ELOQUA_CLIENT_SECRET,
ELOQUA_API_COMPANY,
ELOQUA_API_USER: eloquaApiUser,
ELOQUA_API_PASSWORD: eloquaApiPassword
} = process.env;
// Define Zuora and Eloqua configuration objects
const zuoraConfig = {
restApiUser: ZUORA_API_USER,
restApiPassword: ZUORA_API_PASSWORD,
restApiUrl: ZUORA_API_URL
};
const eloquaConfig = {
authorizeUri: ELOQUA_AUTHORIZE_URL,
tokenUri: ELOQUA_TOKEN_URL,
restApiUrl: ELOQUA_API_URL,
restClientId: ELOQUA_CLIENT_ID,
restSecret: ELOQUA_CLIENT_SECRET,
restApiCompany: ELOQUA_API_COMPANY,
restApiUser: eloquaApiUser,
restApiPassword: eloquaApiPassword
};
// Merge request body and query parameters into a single object
const body = event || {};
if (event.body || event.queryStringParameters) {
body = {...body,...event.queryStringParameters,...event.body };
}
// Call Zuora API to retrieve accounts and upload them to Eloqua
ZuoraAccountService.getZuoraAccounts(body, zuoraConfig)
.then(accounts => BulkUploadEloqua.bulkUploadEloqua(accounts, eloquaConfig, body.instanceId, body.executionId))
.then(() => callback(null, {
statusCode: 200,
headers: {
'Content-Type': 'text/plain'
},
body: 'Success!'
}))
.catch(error => callback(error.message || error.body || error, {
statusCode: 500,
headers: {
'Content-Type': 'text/plain'
},
body: `Error: ${error.message}`
}));
} catch (error) {
// Log the error and return a 500 error response
console.error(error);
callback(error, {
statusCode: 500,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
body: JSON.stringify({ Error: error.message })
});
}
}
module.exports = { handler };
This code defines an AWS Lambda function that handles the bulk upload of Zuora account data to Eloqua.
Here's a breakdown:
Initialization:
Event Handling:
handler
function takes an event object, context object, and a callback function as input.Data Processing:
getZuoraAccounts
function from the zuoraExport
module to retrieve account data from Zuora.bulkUploadEloqua
function from the eloquaUpload
module to upload the retrieved data to Eloqua.Response:
TODOs: