Hey guys,
was wondering if you can give some example code for wix-fetch post?
my sample code doesnt seem to be posting.
const url = ‘https://someapiurl ’;
let dataSet = {
firstName:item.firstName,
lastName:item.lastName,
email:item.email,
phone:item.phone,
}
let opt = {
method: ‘post’,
data: JSON.stringify({
dataSet
})
};
return fetch(url, opt)
.then(response => response.json());
1 Like
See the article Accessing 3rd Party Services for information on accessing web services. You can also look at the tutorial How to Send an Email on Form Submission for real-life example.
BACKEND CODE:
export function postSomething(someVariable){
return fetch(“https://your-url-here ”, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
someVariable: someVariable
})
}).then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject(“Fetch did not succeed”);
}
} );
}
FRONT END CODE:
export function button1_click(event, $w) {
postSomething($w(“#text30 ”).text)
.then(httpResponse => {
console.log(“httpResponse: " + httpResponse);
$w(”#text31 ").text = httpResponse;
})
. catch (error => {
console.log(error);
});
}
Hi I am trying to point a coverage map to an address, basically this is the code I am using:
But when I press submit it fails for this error:
InvalidArgumentInvalid argument.POST object expects Content-Type multipart/form-data
Is there something I am missing?
Sorry, but adding code to an HTML component is not a part of the Corvid product (which is what this forum is about). The basics of an HTML component is to put any HTML code in it. That code can be copied from any source that you want, but you need to know the exact code to put there (which is not related to Corvid)… You will need to check with the service provider to find out how to get it work.
codeqto
December 12, 2019, 8:26pm
6
Did anyone find any solution to this?
Did anyone find any solution to this?
Solution to what?
Learn how to access 3rd party services in the article Velo: How to Access 3rd-Party Services with the Fetch API .
A nice simple example to start with is Create a Weather Widget . Also, take a look at the Advanced examples , many of them access 3rd party services. A couple of good examples to start with are: Example: Using the Places API from Google Maps services and Example: Send email with the SendGrid REST interface .
See the 7 examples on the Examples page .
This is an old post and is being closed.