API in Postman is working but not on Wix

Hi,

I was trying an API which have json payload to send. I’ve write the code and run in the postman and it’s returning accurate results. But as now I’m using the code in Wix but getting error (screenshot attached). I’ve faced this issue for the first time & this kind of error as well.

import { fetch } from 'wix-fetch';

export async function testAPI() {
    const secApiUrl = 'https://{URL here}/Registration';
    let bodyRequest = JSON.stringify({
        "UserId": "******",
        "MemberCode": "*****",
        "Password": "*******",
        "RegnType": "NEW",
        "Param": "T0004|Par||Kuma|01|M|01/01/1970|01|SI|||||||||||||N||||AFEPK2130F||||||||P||||||||SB|11415||HDFC0000001|Y|||||||||||||||||||||FirstName LastName|01|ADD 1|ADD 2|ADD 3|MUMBAI|MA|400001|INDIA|22721233||||test4@test.com|P||||||||||||9999999999|||||||||||||||||||K||||||||||||N||P|||SE|SE|",
        "Filler1": "",
        "Filler2": ""
    })

    let requestOptions = {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                "Authorization": "Bearer ******"
            },
            body: bodyRequest,
        }
        try {
       let response = await fetch(secApiUrl,requestOptions)
       let finalResponse = await response.text();
       return finalResponse;
        } catch (error){
                console.log(error);
                console.log(error.message);
                throw error;
        }
       
}

Install → AXIOS ← (NPM-Package) and use it instead of using the Wix-Fetch and you will have less problems.

Hey, it’s working. I just was considering to get this done via node-fetch or other modules. But I was worried about the security. Is the Axios is safe to use?

I do not know how secure AXIOS is, but it is a very stable NPM-Package, saving you a lot of experemental time while working with http-requests.

I think the more you will use it → the more you will love it.
Give a feedback about AXIOS security if you use it. :wink: