1. Home
  2. Docs
  3. PixelSnapAI Documentation
  4. Example Code
  5. Javascript


# PixelSnapAI API JavaScript Example

This documentation provides an example code snippet in JavaScript for using the PixelSnapAI API to upload and analyze an image. Follow the steps below to run the code successfully.

## Prerequisites

Before running the code, ensure that you have the following:

- Node.js installed on your system.

## Code Example

const axios = require('axios');
const fs = require('fs');

const url = "URL_END_POINT";
const headers = {
  'Authorization': 'Token [SECRET_KEY]'

const uploadAndAnalyzeImage = async () => {
  try {
    const response = await axios.post(url, {
      data: {
        picture: fs.createReadStream('./product_img.jpeg')
      maxContentLength: Infinity,
      maxBodyLength: Infinity
    // Check if the request was successful (HTTP status code 200)
    if (response.status === 200) {
      const { message, product_name } = response.data;
      console.log('Message:', message);
      console.log('Product Names:', product_name);
    } else {
      console.log('Error:', response.data);
  } catch (error) {
    console.error('Error:', error.message);


Running the Code

Follow these steps to run the provided code:

  1. Open a text editor or an integrated development environment (IDE) of your choice.
  2. Copy and paste the code into a new JavaScript file.
  3. Make sure you have the image file product_img.jpeg available in the same directory as your JavaScript file.
  4. Replace the placeholder value 'Token [SECRET_KEY]' in the Authorization header with your actual PixelSnapAI API token. This token can be obtained from your PixelSnapAI account after subscribing to a plan.
  5. Save the file with a .js extension, for example, pixelsnapai_example.js.
  6. Open a terminal or command prompt and navigate to the directory where the JavaScript file is saved.
  7. Run the JavaScript file by executing the command: node pixelsnapai_example.js.
  8. The code will send a POST request to the PixelSnapAI API, uploading the image and returning the response.
  9. The response will be printed to the console, displaying the analysis results or any error messages received from the API.

Return Example

When the API request is successful, the code will receive a JSON response similar to the following:

jsonCopy code{
    "message": "Picture uploaded successfully.",
    "product_name": [
        "Dualshock 4",
        "PS4 DualShock 4",
        "Pro Wireless GamePad",
        "Nuc Controller Plus"

The returned JSON includes a "message" field indicating the success status and a "product_name" field containing a list of product names extracted from the uploaded picture.

Make sure to adjust the code as needed to handle the response according to your application’s requirements.


You have successfully run the JavaScript example code for utilizing the PixelSnapAI API to upload and analyze an image. This code demonstrates the process of making a POST request to the API endpoint and handling the response.

For further information on the available API endpoints, request parameters, and response formats, please refer to the official PixelSnapAI API documentation on the PixelSnapAI website.

If you encounter any issues or have additional questions, please contact our support team at info@pixelsnapai.com. We are here to assist you!

Was this article helpful to you? Yes No

How can we help?