Search code examples
node.jsjsonimage-upload

Save data from others API nodeJS


I have an API to read the information from an identity card (KYC) but this API from another part and I paid for the part to use this API (This API is "you take the picture of your ID card then this API will generate a JSON file with the information of the ID card- I show it below). I would like to save the information I get when I import the image of the Identity card to my Database. It's like creating an API contain the API which I paid. with Input is an Image and output is the data saved to my database. I do it in Nodejs. I need to upload an image then the image will be sent to the API which I paid then This paid API export a JSON file and then that JSON file will be saved to my Database. Please help me or tell me the keyword for my research. The JSON File.

{
    "errorCode": 0,
    "errorMessage": "",
    "data": [
        {
            "id": "024778631",
            "id_prob": "98.57",
            "name": "TRẦN TUẤN LINH",
            "name_prob": "98.41",
            "dob": "03/09/1989",
            "dob_prob": "98.27",
            "sex": "N/A",
            "sex_prob": "N/A",
            "nationality": "N/A",
            "nationality_prob": "N/A",
            "home": "CẨM ĐÔNG, CẨM PHẢ, QUẢNG NINH",
            "home_prob": "99.08",
            "address": "472 CMT8, PHƯỜNG 11, QUẬN 3, TP HỒ CHÍ MINH",
            "address_prob": "96.30",
            "type_new": "cmnd_09_front",
            "address_entities": {
                "province": "HỒ CHÍ MINH",
                "district": "QUẬN 3",
                "ward": "PHƯỜNG 11",
                "street": "472 CMT8"
            },
            "doe": "N/A",
            "doe_prob": "N/A",
            "overall_score": "99.22",
            "type": "old"
        }
    ]
}

I show the API I paid in this picture.enter image description here


Solution

  • Now let’s suppose you’re using this API as a client, it would return you the above mentioned data. Though, how you save the data upon the database is on you either from a client or directly from a server.

    As a client:

    1. Call the api using axios.
    2. Call your api(you can make one in express) and send it the JSON you have received.
    3. This API on your server would convert the JSON keys as columns and the values as a record, that is daved in your database.

    As a server:

    1. You can create a route on your API that makes an axios HTTP request to the API you’re paying for, i.e api.fpt.io to obtain the JSON data.
    2. After that it parses the response stores it in the database and returns the response of your choice, probably the copy of JSON data itself.