NODE.js Example

Version 1.7 (อัพเดทล่าสุด 26 มีนาคม 2024)

File Example

				
					    const axios = require("axios");
    const fs = require("fs");
   
    const testFile = async () => {
      try {
        const branchId = "<YOUR_BRANCH_ID>";
        const apiKey = "<YOUR_API_KEY>";
        const path = "<YOUR_IMAGE_FILE_PATH>";
   
        const buffer = fs.readFileSync(path);
   
        const res = await axios.post(
          `https://api.slipok.com/api/line/apikey/${branchId}`,
          {
            files: buffer,
            log: true,
            // amount: number, // Add this to check with amount of the slip
          },
          {
            headers: {
              "x-authorization": apiKey,
              "Content-Type": "multipart/form-data",
            },
          }
        );
        // Handle success slip
        const slipData = res.data.data;
        console.log(slipData);
      } catch (err) {
        // Handle invalid slip
        if (axios.isAxiosError(err)) {
          const errorData = err.response.data;
          console.log(errorData.code); // Check error code
          console.log(errorData.message); // Check error message
          return;
        }
        console.log(err);
      }
    };
   
    testFile();
				
			

Data Example

				
					   const axios = require("axios");
   
    const testData = async () => {
      try {
        const branchId = "<YOUR_BRANCH_ID>";
        const apiKey = "<YOUR_API_KEY>";
        const qrString = "<YOUR_QR_STRING>";
   
        const res = await axios.post(
          `https://api.slipok.com/api/line/apikey/${branchId}`,
          {
            data: qrString,
            log: true,
            // amount: number, // Add this to check with amount of the slip
          },
          {
            headers: {
              "x-authorization": apiKey,
            },
          }
        );
        // Handle success slip
        const slipData = res.data.data;
        console.log(slipData);
      } catch (err) {
        // Handle invalid slip
        if (axios.isAxiosError(err)) {
          const errorData = err.response.data;
          console.log(errorData.code); // Check error code
          console.log(errorData.message); // Check error message
          return;
        }
        console.log(err);
      }
    };
   
    testData();

				
			

Url Example

				
					    const axios = require("axios");
   
    const testUrl = async () => {
      try {
        const branchId = "<YOUR_BRANCH_ID>";
        const apiKey = "<YOUR_API_KEY>";
        const url = "<YOUR_IMAGE_URL>";
   
        const res = await axios.post(
          `https://api.slipok.com/api/line/apikey/${branchId}`,
          {
            url,
            log: true,
            // amount: number, // Add this to check with amount of the slip
          },
          {
            headers: {
              "x-authorization": apiKey,
            },
          }
        );
        // Handle success slip
        const slipData = res.data.data;
        console.log(slipData);
      } catch (err) {
        // Handle invalid slip
        if (axios.isAxiosError(err)) {
          const errorData = err.response.data;
          console.log(errorData.code); // Check error code
          console.log(errorData.message); // Check error message
          return;
        }
        console.log(err);
      }
    };
   
    testUrl();