Skip to content
/ ae_sdk Public

A simple SDK for Aliexpress (dropshipping and affiliate) APIs.

License

Notifications You must be signed in to change notification settings

moh3a/ae_sdk

Repository files navigation

Aliexpress SDK npm version

Typescript CI Publish Downloads Bundle Size License

A simple and type-safe SDK for Aliexpress (system tools, dropshipping and affiliate) APIs.

Overview

Aliexpress launched a new open platform to consume their APIs. They fully migrated and upgraded their services from the old Taobao Open Platform to the new Open Platform for International Developers. The issue is, with this update, they have yet to release a Node.js SDK.

Features

This library is an unofficial and simple SDK that can do the following:

  • Compose a request, generate an encryption (method signature) and interprete the response.
  • Pass the right parameters for your API call with type safe methods.
  • Currently supports the system tools for authentication, Affiliate API and Dropshipping API.

Installation

# using npm
npm i ae_sdk

# using pnpm
pnpm add ae_sdk

# using yarn
yarn add ae_sdk

Prerequisites

Before you can start using this SDK you should start with the following steps:

Become a developer

You must have an Aliexpress account or create one, and then register as a developer through this link. For more details.

Register an application

After creating your developer account, you can start registering a new applicationon by following the steps details in the following link.

Retrieve App Key and App Secret

Once your application is registered, the app_key and app_secret are assigned to the application automatically. These parameters must be included in every AE API request. For more details on how to retrieve them, visit.

Retrieve the access token

In order to access Aliexpress sellers’ business data, the application needs to get the authorization from sellers, and you need to guide them to complete the flow of “using Aliexpress seller account to log in and authorize”. Follow the steps detailed in this link to get your access token. It must included in every AE API request.

Usage

Using the dropshipping client in this example

Initialize a client

After retrieving the required parameters to initialize a new client, you do the following:

import { DropshipperClient } from "ae_sdk";

const client = new DropshipperClient({
  app_key: "123",
  app_secret: "123456abcdef",
  session: "oauth_access_token",
});

Write your first AE API method

With your client initialized, you're all set up. For example, you can retrieve a certain product's details:

await client.productDetails({
  product_id: 1005004043442825,
  ship_to_country: "DZ",
  target_currency: "USD",
  target_language: "en",
});

Your API response

All API calls, if successfull will return a boolen ok and a data with the response body. The following is an example response for the above API request:

{
  "ok": true,
  "data": {
    "aliexpress_ds_product_get_response": {
      "result": {...},
      "rsp_code": 200,
      "rsp_msg": "Call succeeds",
      "request_id": "..."
    }
  }
}

If not successfull, you will either get:

{
  "ok": false,
  "message": "Bad request.",
  "request_id": "..."
}

In this case, you should make sure you correctly passed the right parameters. If the problem persists, please contact me with request_id. Or you will get the following error:

{
  "ok": false,
  "message": "Internal error."
}

Hopefully, it won't happen 🙃

Directly call the API

If you wish to call a different Aliexpress API that is not by the current version. You can do the following:

const result = await client.callAPIDirectly("aliexpress.api.endpoint", {
  [string]: string | number | boolean,
});

Examples

AE Affiliate Client

Generate an affiliate link

In order to generate an affiliate link for Aliexpress products that are registered in the affiliate program.

await client.generateAffiliateLinks({
  // 0 for a normal link, 2 for hot link which has hot product commission
  promotion_link_type: 0 | 2,
  // original aliexpress product's link
  source_values: "...",
  tracking_id: "...",
  app_signature: "...",
});

Query hot products

To search for high commission affiliate products.

await client.getHotProducts({
  app_signature: "...",
  keywords: "watch",
  page_no: 1,
  page_size: 50,
  platform_product_type: "ALL",
  ship_to_country: "US",
  sort: "SALE_PRICE_ASC",
  target_currency: "USD",
  target_language: "EN",
  tracking_id: "...",
});

Dropshipper client

Product shipping details

Get the shipping details for any product.

await client.freightInfo({
  country_code: "DZ",
  send_goods_country_code: "CN",
  product_id: 123456,
  product_num: 1,
});

Create an order

In order to place an order.

await client.createOrder({
  logistics_address: {
    address: "...",
    city: "...",
    country: "DZ",
    full_name: "Bou Ben",
    mobile_no: "0555 66 77 88",
    phone_country: "+213",
    zip: "16000",
  },
  product_items: [
    {
      logistics_service_name: "...",
      order_memo: "This is a dropshipping order.",
      product_count: 1,
      product_id: 123,
      sku_attr: "...",
    },
  ],
});