I use this code to send contact to activecampaign:
Backend
import { fetch } from 'wix-fetch';
export function getApiKey() {
const key = 'Key';
const name = 'giovanni';
const email = 'giovanni@gmail.com';
const URL = 'url';
return fetch(URL, {
'method': 'post',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded',
'api-key': 'key'
},
'contact': {
'first_name': name,
'email': email
}
})
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
})
.then((json) => console.log(json.someKey))
.catch(err => console.log(err));
}
Page
import {getApiKey} from 'backend/activecampaign.jsw'
$w.onReady(function () {
getApiKey();
});
But it return me this error:
invalid json response body at http://…/admin/ reason: Unexpected token < in JSON at position 1
How can i fix?