Unexpected token < in JSON at position 0"

Dear forum members, I am absolutely new with WIX and CORVID and I am not a programmer. I have a problem which I could not solve by myself, for which I would appreciate your help very much. My target is to get an “MD5-Hash” (=Licencekey) for a given Input (=ProductKeyInput) in my web-page. The “MD5-Hash” can be get by an 3 party API (URL). I have already managed this target by myself with the following code (at page level) which works fine:

import { getJSON } from ‘wix-fetch’ ;

$w.onReady( function () {
// page related code here…

$w( ‘#UpdateLicenceKeyButton’ ).onClick((event) => {
DetermineLicenceKey();
})
}
);

function DetermineLicenceKey() {

const url = “ https://helloacm,com/api/md5/?cached&s=" ;
let salt = “Salz”
let ProductKeyInput = $w( “#PRODUCTKEY” ).value;
let fullUrl = url + ProductKeyInput + salt;

getJSON(fullUrl)
.then(Licencekey => {$w( “#LICENCEKEY” ).value=Licencekey;})

}

But my solution is not fulfilling the security aspects at all. I need the determination of the “MD5-Hash”(=Licencekey) in the backend, for a provided input in the front end. Unfortunately I could not solve this problem by myself. In the following I am showing you my backend and frontend codes. My solution is ending with the error “Unexpected token < in JSON at position 0”.

// backend/…

import {fetch} from ‘wix-fetch’ ;

export function LicenceKey(ProductKey) {

const url = “https://helloacm,com/api/md5/?cached&s=” ;

const salt = “salz” ;

let fullUrl = url + ProductKey + salt;

fetch(fullUrl, {method: ‘get’ })
.then(response => response.json()) // response.text() or response.json()?

}

//Frontend page code

import {LicenceKey} from ‘backend/aModule-3’ ;

export function buttonFetchLKEY_click(event) {
LicenceKey($w( “#textInputProductKey” ).value)
.then(result => $w( “#textBox1” ).value = result);
}

Please explain what you are trying to do, what works, what doesn’t, and share your code.

I am really getting very frustrated with the forum tool. I am not able to post more than the header. When I am writing more and I did this many many times already I receive a message that I am currently not allowed to share links. Which I do not understand at all.

Any Ideas how to get solved this?

Thanks

Cemail

@cemailtatari Please post your code without incuding links (URLs).

Hi Israel,

I am receiving this Info, when I am trying to post more text in:

“Your account does not currently allow posting of links. If you need to post a link of your site or relevant Wix content, you can “break” the URL by adding spaces, like this: www.wix . com/corvid”

I am absolutly not including links (URLs)

By the way I am also getting many many e-mail from the community with questions, I do not want to see and receive. Something must be absolutly going wrong with my account.

Can you help?

When I check the activity, you have helloacm,com, which is a link, in your code that you are trying to post. Take the links out of your code, or “break” them by using commas instead of dots.

Also, you can configure the email notifications that you receive from your account.

@yisrael-wix

Thank you for your help with the breaking of URLs in my codes to be able to publish.

Now I am looking forward for the solution of the original problem I have. :grinning:

Hey Cemail!

The issue you’re getting is that the api endpont is returning an HTML page, instead of a nice JSON object. That’s what’s triggering the error with “Unexpected token…”, because it’s looking for JSON and finding “<html…”.

What you can do is test the endpoint again, and failing that, use fetch instead of getJSON from wix-fetch. I’ve had that exact same error as you when using getJSON, even with valid apis.

Orrrrrrrrr, the better option by far (in my thinking) is this. You can actually install the md5 NPM package and do the hashing natively on your site, in either backend or front-end code, no requests to a 3rd party needed at all!! Much cleaner, more control and less vague errors to figure out. Backend would be my suggestion

@chris-derrell Thank you very much for your detailed answer and your recommendation regarding the implementation of the md5 NPM package for handling the hashing natively in my site, which I would appreciate as the best solution. But is this something I can do by my own as a non programer, a beginner? is there somewhere an easy documentation, cooking book for Wix and Corvid beginners without having programming capabilities how to install the package and implement the functionalities in the Backend with parameter access from the Frontend?

@Chris Derrell Thank you very much for your comprehensive answer to my problem. In particular I would like to thank you for your very good advice to use the md5 NPM package, instead of referring to a 3rd party API and application.

I would like to share my progress with the community following this good recommendation. When I used the md5 functionality after installation of the md5 NPM package, which I have been using in the first step only on the frontend of my client, I was able to get the expected results successfully.

Here the Code:

// Frontend only


import { getJSON } from 'wix-fetch';



var md5 = require('md5');                          
//The message you receive in the editor refering to "require" is a warning and can be ignored due to Corvid Team
//as seen in the corvid forum under "Help with importing npm packages"


$w.onReady(function () {
 // page related code here...
 
$w('#UpdateLicenceKeyButton').onClick((event) => {    
    DetermineLicenceKey();
 
})});



function DetermineLicenceKey() {
  let ProductKey = $w("#PRODUCTKEY").value;
 
 let Salt = "Salz"
 let ModProductKey = ProductKey + Salt;
 
 let MyLicenceKey = md5(ModProductKey);
  $w('#MyLicenceKey').value=MyLicenceKey; 
}


As mentioned earlier, for security reasons the implementation of my code has to follow a backend + frontend solution. In the backend, the function to determine a LicenceKey depending on a variable ProduktKey has to be implemented. In the second step this function must be called in the frontend where the ProductKey as a variable has to be inputted to receive the LicenceKey. In the following the codes in backend and as well in the frontend are shown.
Unfortunately I receive an error “Maximum call stack size exceeded” in the line starting with “export function MyLicenceKey(ProductKey) {” .
Here I definitely need the help from the Corvid community:

// Backend Code for LicenceKey

var md5 = require('md5');       
 
export function MyLicenceKey(ProductKey) {
 
 let Salt= "salz";
 let ModProductKey= ProductKey + Salt;
 

 return MyLicenceKey(ProductKey).value=md5(ModProductKey).value;

}

// Frontend Code calling the required function Licencekey from // Backend

import { getJSON } from 'wix-fetch';
import {MyLicenceKey} from 'backend/MyHash';


$w.onReady(function () {
 // page related code here...
 
$w('#UpdateLicenceKeyButton').onClick((event) => {    
    DetermineLicenceKey();
 
})});



function DetermineLicenceKey() {
 
 
 let ProductKey = $w("#PRODUCTKEY").value;


$w('#MyLicenceKey').value = MyLicenceKey(ProductKey);

}


I receive an error “Maximum call stack size exceeded”, in my backend code at line 6 with the code statement “export function MyLicenceKey(ProductKey) {” for which I need the help from the Corvid community.

@yisrael-wix Hi Yisrael, I have a question to you as a moderator of this forum: Yesterday I got a very good answer to my initial question I posted. After following the recommendation made by Chris Derrell to my question, I have been getting a new problem which I added up to the already existing post. Should I maybe open a new post " Maximum call stack size exceeded" to get a quick support ?
I am just afraid not to get a support for this new issue and getting stucked with the problem.

Thank you very much for checking this with a good advice from you. :grinning:.

Glad to hear that it was a helpful start @cemailtatari !

That error usually comes up when you function is stuck in a nice function self-call loop, where a function is calling itself again over and over.

In your case, that happens here :

// Backend Code for LicenceKey

var md5 = require('md5');       
 
export function MyLicenceKey(ProductKey) {
 
 let Salt= "salz";
 let ModProductKey= ProductKey + Salt;
 

 return 
 -->MyLicenceKey(ProductKey)<-- .value=md5(ModProductKey).value;

}


What your backend file, ‘backend/MyHash’, could be instead is below:

// Backend Code for LicenceKey

var md5 = require('md5');       
 
export function MyLicenceKey(ProductKey) {
 
 let Salt= "salz";
 let ModProductKey= ProductKey + Salt;
 

 return md5(ModProductKey); //Removing all unnecessary extra code, except for the message digest hashing function.

}

This should give you back the MD5 function you’re looking for with the hash of the Product Key, concatted to the Salt.

Since MD5 is more or less globally the same, you should be able to test if this gives you the values you expect.

@chris-derrell

Hi Chris, Thank you very much for your support. It helped me a lot, although I had as well other problems to solve until I got the complete correct results I expected. The concatenated “SALT” variable I was using is something which as well changes automatically from time to time according to a logic. This caused a lot of further trouble to solve. Any way. After I complete some of the other issues, hopefully by myself, I am thinking to work with an professional support. I do not know how much support I will need to finalize my webpage functionalities and as well I do not know how much help I require to keep it later a live, but would you generally be interested to work with me and my brother from time to time to get our new business starting and developing? If yes, can you provide me any figures, how much you are charging for your professional services. Beside this, I am thinking of the different time zones between Berlin, Germany where I am located, Washington DC, where my brother is located who will participate on driving the daily business an a later stage and your nice location from which you maybe like to support us from time to time. Do you have already any experience working for other time zones?
For any case, I provide you my private email Cemail.Tatari@gmail.com However thank you again for your help so far. Best Regards from Berlin Cemail

Hey Cemail, I’ll reach out to you now