How to search Aliexpress products by image thanks to Halios-data's API in Javascript/NodeJS




The purpose of this article is to explain how you can search products from aliexpress with an image URL.

We will use nodeJS to consume the API

This feature can be interesting for your dropshipping website by integrating a more user-friendly search.

You also can download the project from git https://github.com/HaliosData/search-aliexpress-product-by-image.


Search the products with the API

Create an account to RapidAPI

Today, you need to create an account to RAPIDAPI to consume the API, but don't worry, you can use your Google or Github account ;).


Subscribe to the API



After the login, you are generally redirected to the API hub. Else click here

You can test the API for free with 5 requests per month for search products by image else 500 for other endpoints. Click on the subscribe button and choose the Basic plan.

















API Using

To communicate with the API, we will use Axios during this example.


First, install it thanks to npm. We implement the communication with the API in the app.service.ts with Axios lib inside the service.


We inject the library at the top of our service.

import { Axios } from 'axios';


We add the method that communicates with the API and returns the products from an image URL.

I call this one getData, and I inject in the method a parameter URL.


getData(url: string): { message: string } { let products; return products; }

In order to realize the communication with the API, I'm creating a private method with a parameter.

private async getProductsFromImage(url: string) {


In the method, I'm implementing the communication with the API.

private async getProductsFromImage(url: string) { try { var aliexpressProducts = await this.axios.request({ method: 'GET', url: 'https://magic-aliexpress1.p.rapidapi.com/api/products/searchByImage', params: { url: url }, headers: { 'x-rapidapi-host': 'magic-aliexpress1.p.rapidapi.com', 'x-rapidapi-key': 'YOUR_TOKEN' } }) } catch (e) { throw e; } return JSON.parse(aliexpressProducts.data); }

And now, in the public method, I can call my private method with the image URL communicated by the controller.


async getData(url: string): Promise<any> { let products; products = await this.getProductsFromImage(url) return products; }


It is now enough to communicate the URL of the controller to the service.


async getData(@Query('url') url) { return await this.appService.getData(url); }


Consume the API


Now I can ask my API to return the products with an image.


http://localhost:3333/api/?url=https://images.brax.com/im/b2c/6_desktop1x/brax-614055/851737_7163220_56_4_6_AB.jpg


And the API returns


{ "data": { "dto": { "categorys": [ { "id": 0, "name": "Apparel", "selected": true }, { "id": 3, "name": "Luggage & Bags", "selected": false }, { "id": 4, "name": "Shoes", "selected": false }, { "id": 88888888, "name": "Others", "selected": false } ], "items": [ { "imgWidth": 350, "productId": 1005001710015939, "subject": "Autumn Winter Men`s Thick Warm Corduroy Pants Fleece Trousers Male Casual Business Style Long Jeans Men", "marketingPrice": { "appPrice": { "discount": 0, "price": { "currency": "USD", "formatedAmount": "US $18.49", "value": 18.49 } }, "bigSalePrice": null, "pcPrice": null }, "logistics": null, "debugInfo": null, "promotionTag": null, "union": null, "plusInfo": null, "type": "ImageSearchProduct", "p4p": null,


Thank you and good scraping :)







28 views0 comments

Discover Halios-Data solution for the web scraping

More Halios-Data

Never miss an update

Thanks for submitting!