Hi.
I followed the tutorial here: https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api
But i can’t seem to get it to work. I’m testing out the https://www.apixu.com weather api purely as i’m a novice with this and im trying to learn new skills with wix.
I created the button, search bar ( User input ) and a text box for the results to show in. I then named them all accordingly. I also created a data sheet and added the both text data, but wasn’t sure if i needed to add another one for the button? If so, what field type do i use?
Here is the page code i used:
//Form’s page code import {getCurrentTemp} from ‘backend/serviceModule’; //… export function buttonFetchTemp_click(event) { getCurrentTemp($w(“#textInputCity”).value) .then(temp => $w(“#textTemp”).text = temp + “°”); }
and here is the backend code i used
//serviceModule.jsw
import {fetch} from 'wix-fetch';
export function getCurrentTemp(city) {
const url = 'https://api.openweathermap.org/data/2.5/weather?q=';
const key = '<api key placeholder>';
let fullUrl = url + city + '&appid=' + key + '&units=imperial';
return fetch(fullUrl, {method: 'get'})
.then(response => response.json())
.then(json => json.main.temp); }
Can anyone help with this please?