Hi Corvid Forum,
We are doing an API integration and are running into an issue. We are getting back two responses from the WIX code and we just need one response for the integration to work. The second response (automatic refresh) makes it so we are losing the integration token. Do you have a solution?
The issue further explained:
The first response is received right away
The second response is being delivered after the entire content of the page has been loaded (2-5 seconds later)
Reviewing the code, we see the following:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
$w.onReady(function () {
//TODO: write your page related code here…
});
Which means the correct way would be to receive only one response → when entire content is loaded
No response should be provided until the page is loaded.
Please review the WIX code for the homepage:
import wixLocation from ‘wix-location’;
import { getCleverToks } from ‘backend/app.jsw’;
// …
$w.onReady( function () {
let query = wixLocation.query; //
if (query[‘code’]) {
console.log(query[‘code’]);
getCleverToks(query[‘code’])
.then((json) => {
console.log(json);
}). catch (err => {
console.log(err);
});
}
});
**app.jsw - **
import { fetch } from ‘wix-fetch’;
export function getCleverToks(code) {
return fetch(’ https://bookjobsnow.com/app_clever.php?code= ’ + code, {
“method”: “get”,
“headers”: {
“Authorization”: “Bearer 123”
}
})
.then((httpResponse) => {
return “Bearer 123”;
});
}
thank you for your help in fixing this issue,
Dan