Hi I am trying to integrate and api to a site but facing an issue my code is giving me an authentication error dont know where I am doing wrong please help if anyone knows the solution.
Here is the code on the backend createUser.jsw
import { fetch } from ‘wix-fetch’ ;
import encode from “nodejs-base64-encode” ;
export async function CreateUser ( UserInfo ) {
const customer_id = “pcswireless-PKA35J.FC5OO3” ;
const token = “9e0f6118-b9c6-4338-b838-eeae15d2a805” ;
const response = await fetch ( “https://test.connect.boomi.com/ws/rest/masterdealer/users” , {
method : ‘post’ ,
headers : {
“Authorization” : 'Basic ’ + encode . encode ( customer_id + “:” + token ),
‘Content-Type’ : ‘application/json’
},
body : JSON . stringify ({ UserInfo })
});
if ( response . status >= 200 && response . status < 300 ) {
const json = await response . json ()
return json . id ;
}
const responseText = await response . text ();
console . log ( responseText );
return response . status ;
}
and here is my front end code
import { fetch } from ‘wix-fetch’ ;
import { CreateUser } from ‘backend/createUser’ ;
$w . onReady ( function () {
});
export function button1_click ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
CreateUser ( creatUser ())
. then (( Userinfo ) => {
});
}
function creatUser ( ) {
return {
“firstName” : $w ( “#firstName” ). value ,
“lastName” : $w ( “#lastName” ). value ,
“email” : $w ( “#email” ). value ,
“company” : $w ( “#companyName” ). value ,
“value” : $w ( “#pass” ). value ,
“question” : $w ( “#recoveryQues” ). value ,
“recoveryAns” : $w ( “#recoveryAns” ). value
}
}
that is the page url
https://www.primocelstore.com/user-info
that is the error I am getting
Loading the code for the Create User page. To debug this code, open or98m.js in Developer Tools.
HTTP ERROR 401
Problem accessing /ws/rest/masterdealer/users. Reason:
UNAUTHORIZED - Could not decode Authorization