lazada-iop-client
v1.1.1
Published
Lazada IOP Client SDK for Node JS
Downloads
72
Maintainers
Readme
Lazada IOP SDK for Node JS
Lazada SDK for JavaScript allows you to interact with the Lazada API easily. This SDK supports features such as authentication, sending API requests, and file handling.
Features
- OAuth2 Authentication: Generate an authentication URL for users to authorize your application.
- API Requests: Send API requests to the Lazada server with the provided parameters.
- API Signature: Sign requests for security and data integrity.
- File Support: Upload files to the Lazada API using FormData.
Installation
To get started, install the following dependencies:
pnpm add axios form-data cryptoUsage
1. Create an Instance of LazadaClient
To begin using this SDK, create an instance of LazadaClient and provide the required parameters.
import LazadaClient from "./LazadaClient";
// Create an instance of LazadaClient
const client = new LazadaClient({
apiKey: "YOUR_API_KEY",
apiSecret: "YOUR_API_SECRET",
region: "SG", // Example: 'SG', 'MY', 'VN', etc.
callbackUrl: "YOUR_REDIRECT_URL",
});2. Authentication
To get the authentication URL, use makeAuthURL. The user will be directed to this URL to grant access to your app.
const authURL = client.makeAuthURL();
console.log(authURL); // Direct the user to this URL to login3. Set Access Token
After the user grants permission and your app receives the authorization code, you can set the access token to the LazadaClient instance.
client.setAccessToken("YOUR_ACCESS_TOKEN");4. Add API Parameters
You can add API parameters that will be used in the API request.
client.addAPIParam("key", "value");
client.addFileParam("file_key", fileBuffer);5. Execute API Requests
To send an API request to Lazada, use the execute method with the API path and HTTP method.
const response = await client.execute("/path/api", "GET", { key: "value" });
console.log(response);6. Change Region
If you need to change the region where you want to access the Lazada API, you can do so with the changeRegion method.
client.changeRegion("MY"); // Change to MalaysiaFull Example
import LazadaClient from "./LazadaClient";
const client = new LazadaClient({
apiKey: "YOUR_API_KEY",
apiSecret: "YOUR_API_SECRET",
region: "SG",
callbackUrl: "YOUR_REDIRECT_URL",
});
// 1. Get the authentication URL
const authURL = client.makeAuthURL();
console.log("Redirect the user to the following URL:", authURL);
// 2. After getting the access token, set the token
client.setAccessToken("YOUR_ACCESS_TOKEN");
// 3. Add API parameters
client.addAPIParam("someKey", "someValue");
// 4. Execute the API request
client.execute("/some/api/path", "GET").then((response) => {
console.log("Response from the API:", response);
});Directory Structure
project/
│
├── src/
│ └── index.ts # Main SDK code
├── example.ts # Example usage of the SDK
├── package.json # Project and dependencies information
└── tsconfig.json # TypeScript configurationContribution
If you want to contribute, please open a pull request or create an issue for any problems or suggestions.
License
This SDK is licensed under the MIT License.
Make sure to replace placeholders like YOUR_API_KEY, YOUR_API_SECRET, and YOUR_REDIRECT_URL with your actual project information.
