I’m struggling to get a post API call to work, it always responds immediately with TypeError. How can I get more details behind the error to diagnose it?
Is this your final code? Because this code is for POST, usually when you are trying to access something, you need to GET. Then, you need to put an url .
Like this:
import { fetch } from "wix-fetch"
export function createbutton_click(event) {
const url = "https://jsonplaceholder.typicode.com/todos/1"
let fetching = fetch(url, {
method: "GET"
})
.then(httpsResponse => {
if (httpsResponse.ok) {
return httpsResponse.json().then(data => data)
} else {
return Promise.reject("Fetch did not succeed")
}
})
.then(response => console.log(response)) //This is the response
.catch(error => {
console.log(error)
})
}