3rd party API integration

I am trying to communicate with a 3rd party API. I wrote the API in python. I want to update the name column in the database from the Wix web page using a user form and text box. The database updates and all of the endpoints are responsive using postman to test. I think the problem resides in my JavaScript on the Wix end.

I modeled the JavaScript from the Wix example at:

I have a back end module called placeOrder stored in orderplaced.jsw that should post the variable ‘name’ to the api.

import { fetch } from ‘wix-fetch’;
// wix-fetch is the API we provide to make https calls in the backend

export function placeOrder(name) {
return fetch(“https://mysite.pythonanywhere.com/user”, {
method: ‘post’,
name: JSON.stringify({ name })

}).then(function (response) {
if (response.status >= 200 && response.status < 300){
console.log(JSON.stringify({ name }))
return response.text();}

console.log(Error(response.statusText))

return Error(response.statusText);}

);
}

The front end module waits for a button click and stores the text box in the name variable.

{
import {placeOrder} from ‘backend/orderplaced.jsw’;

export function button1_click(event, $w) {
placeOrder(
$w(“#input1”).value)

.then(function() {
console.log(“Form submitted to backend.”);
}
);
}
}

Output:


The code appears to be reaching the back end. I believe the problem is in my placeOrder function as I am not very familiar with JavaScript.

Hi

Worked fine (at least technically, response = 200) with a few changes.

export function placeOrder(name) {
 var body ={
 "name":name
    };
 return fetch("https://reliableeparts.pythonanywhere.com/user", {
 "method": "post",
 "body": JSON.stringify(body), "headers": { "Content-Type": "application/json"}
 
        }).then(function (response) {

Worked great thank you.

Looking for a coder to assist with API coding for 3rd party fulfillment site. Have detailed documentation to accomplish. Please let me known if anyone has any suggestions

Please stop bumping up old threads, if you have an issue with your own code then add a new forum post of your own instead of bumping up old posts from 2018 here and here https://www.wix.com/corvid/forum/community-discussion/router-pages-time-outs-issue