Please can you help me to get an API to work that works in Postman, but I can’t get to work in WIX.
I have a GET request working, but the POST request gives an error “JSON error: Syntax error”
I’ve spent a couple of hours trying to get this to work, it’s the first time I’m working with API’s so it may be that I’m missing something straightforward.
This is the working GET request:
import {fetch} from 'wix-fetch';
export function checkAuthorization() {
console.log('checking...')
var myHeaders = {'authorization': 'Basic EzMDgzMmYxNzE3ZTE5MjBjZGEzYjQyOg=='};
console.log(myHeaders)
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://dash.stannp.com/api/v1/users/me", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
And the not working POST request
import { fetch } from 'wix-fetch';
export function newGroup() {
console.log('checking...')
var myHeaders = { 'authorization': 'Basic EzMDgzMmYxNzE3ZTE5MjBjZGEzYjQyOg==' };
console.log(myHeaders)
var myBody = { 'name': 'My Group' }
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: myBody,
redirect: 'follow'
};
fetch("https://dash.stannp.com/api/v1/groups/new", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
Any help would be appreciated. Thanks