Wix Fetch (Post) - How do I determine what I am Posting?

I am going to try to ask a better question…

curl works correctly but my WIX’ified Fetch Post appears to be malformed.

How do I determine what wix-fetch is actually sending AND what it should be sending?

How do I determine what the fault is rather than continuing to “try things” in hopes of stumbling on a solution.

Thanks,
Robert

Trying to Post some data to FreshSales (crm)
I have proven that I can post using curl.
Now I am trying to Post from WIX.

I am getting a result of httpResonse.text == “Bad Request” // “Fetch did not Succeed”

I have tried playing with JSON.stringify, no stringify, manually providing escapes to now avail.
the Corvid API example leaves me guessing about the structure of the body being posted via wix-fetch. ( “body” : “somekey=somevalue”)

API Example - https://www.wix.com/corvid/reference/wix-fetch.html#fetch

import {fetch} from 'wix-fetch';

// ...

fetch( "https://someapi.com/api/someendpoint", {
  "method": "post",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "body": "somekey=somevalue"
} )
  .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));

data.js

 function updateFreshSales(item, context)
{
  console.log('function updateFreshSales' );

 // Freshsales Example Account Post
 // curl 
 // -H "Authorization: Token token=R0notmykyIhFQ" 
 // -H "Content-Type: application/json" 
 // -d '{"sales_account":{"name":"Wonka"} }' 
 // -X POST "https://ucworkspace.freshsales.io/api/sales_accounts"

 fetch( 'https://ucworkspace.freshsales.io/api/sales_accounts' , {
   'method' : 'post',
   'headers': {
     'Authorization': 'Token token=R0notmykyFQ',
     'Content-Type': 'application/json',
      },
   'body' : JSON.stringify('{"sales_account":{"name":"WONKA"} }')
 })
 .then( (httpResponse) => {
   if (httpResponse.ok) {
     return httpResponse.json();
   } else {
     console.log(httpResponse.text);
     return Promise.reject("Fetch did not succeed");
   }
 } )
 .then( (json) => console.log(JSON.stringify(json)) )
 .catch(err => console.log(err))
 }

‘body’ : JSON . stringify ( ‘{“sales_account”:{“name”:“WONKA”} }’ )

JSON.stringify function converts regular javascript objects to a json string.
you cant convert regular string to json string, it is not how it meant to work,
you should do
‘body’ : JSON . stringify ( {“sales_account”:{“name”:“WONKA”} } ).
let me know if it helped

Hi Gal,

It didn’t but this did
// testing site - [fetch(“https://webhook.site/"](fetch("https://webhook.site/”)

You can see exactly what is getting sent out of wix fetch