API JSON error

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

Solved it.

I needed to use JSON.Stringify() on the body variable and set the content type appropriately.

This helped me work it out:
https://github.com/github/fetch/issues/635#issuecomment-401358597

google

In business, a track record may refer to a company’s financial performance over time, including revenue, profit margins, and growth https://www.academicdissertations.co.uk/case-study