SkyJoy
HomeDocs
  • 👋Welcome to SkyJoy
  • GETTING STARTED
    • Introduction
    • Ground rules for API
    • Authentication
    • Error handling
  • DEVELOPMENT PROCESS
    • Integration model
    • Batch
  • API REFERENCE
    • Authentication
    • Customer
    • Point
    • Transaction
  • WEBHOOK
    • Partner Integration
  • SINGLE SIGN-ON (SSO)
    • iFrame
    • Regular Web App
    • Single Page App
  • VERSION HISTORY
    • Document changelog
Powered by GitBook
On this page
  • Summary
  • Use cases
  • How to upload file
  • File format
  • Error code

Was this helpful?

  1. DEVELOPMENT PROCESS

Batch

Upload batch file to execute loyalty activities

Summary

Update customers' point balances in bulk by uploading a designated file containing the necessary information by using S3 Direct (Nodejs) method.

Use cases

Some of the reasons to use Batch method:

  • Handle a large volume of data at once, making it more efficient than processing individual transactions, especially when dealing with bulk updates to user point balances.

  • Rectify errors in point allocation that might occur with real-time processing.

  • Reduce the load on your server during peak hours, ensuring a smoother user experience for other functions of your application.

  • Schedule batch processes to run at specific times, allowing you to perform routine tasks, such as updating user point balances, during non-peak hours without manual intervention.

How to upload file

To submit the file, follow these steps:

Step 1: Install the AWS SDK v3

Install the AWS SDK v3 for JavaScript using npm:

npm install @aws-sdk/client-s3
Step 2: Configure AWS Credentials

Configure your AWS credentials as described in the previous examples by setting environment variables, using a configuration file, or specifying credentials directly in your code. Here's an example of how you can set up your credentials:

const { S3Client } = require("@aws-sdk/client-s3");
const { fromIni } = require("@aws-sdk/credential-provider-ini");

// Use AWS SDK v3 to create an S3 client
const s3 = new S3Client({
  credentials: fromIni({ profile: "your-aws-profile-name" }),
  region: "your-region",
});

Replace "your-aws-profile-name" (SkyJoy provides profiles to partners) and "your-region" with your actual AWS profile name and desired AWS region.

Step 3.1: Upload a file

To upload a file to an S3 bucket, you can use the putObject method.

const { PutObjectCommand } = require("@aws-sdk/client-s3");
const { createReadStream } = require("fs");

const bucketName = 'your-bucket-name';
const objectKey = 'desired/s3/object/key.txt';
const fileName = 'path/to/your/local/file.txt';

const params = {
  Bucket: bucketName,
  Key: objectKey,
  Body: createReadStream(fileName),
};

s3.send(new PutObjectCommand(params))
  .then((data) => {
    console.log("File uploaded successfully:", data);
  })
  .catch((error) => {
    console.error("Error uploading file:", error);
  });

This code will upload the local file located at fileName to the specified S3 bucket with the object key objectKey.

Step 3.2: Update a file

To update an existing file in S3, you can use the same putObject method with the same object key. It will overwrite the existing file with the new content, just like in the previous example.

s3.send(new PutObjectCommand(params))
  .then((data) => {
    console.log("File updated successfully:", data);
  })
  .catch((error) => {
    console.error("Error updating file:", error);
  });

Make sure to handle errors and adjust the access permissions on your S3 objects as needed. Also, ensure that your AWS credentials have the necessary permissions to perform these operations on the S3 bucket.

File format

Upload file

File format must be CSV with data fields separated by commas ",".

File name format must be: <Name>_<Version>_<YYYYMMDD>_<HHMMSS>.csv

  • Name: Name of the file

  • Version: Version of the file

  • YYYYMMDD: Time as format <year><month><day>

  • HHMMSS: Time as format <hour><minutes><second>

Example: EarnPoint_v0_20230808_000001.csv

Result file

Result file will be uploaded into SkyJoy Storage after the process is done successfully.

Result file name format must be: <Name>_<Version>_<YYYYMMDD>_<HHMMSS>.csv

  • Name: Name of the file

  • Version: Version of the file

  • YYYYMMDD: Time as format <year><month><day>

  • HHMMSS: Time as format <hour><minutes><second>

Template

Partners will provide the secret_key to SkyJoy

Error code

Error detail and explanation when triggering issues for file uploading:

Code

Message

UNSUPPORTED_FILE_FORMAT

Unsupported file format

INVALID_PARAMETER

Invalid data

Last updated 1 year ago

Was this helpful?

Local file must follow below.

Check the CSV upload template file with detailed explanation of data columns .

here
batch file guidelines