# Wix http functions not working but code is working

**URL:** <https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 13, 2019, 7:57am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098 "2019-05-13T07:57:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![waynetheron](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/waynetheron/32/9009_2.png) [@waynetheron](https://forum.wixstudio.com/u/waynetheron)\
**Post date:** [May 13, 2019, 7:57am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098/1 "2019-05-13T07:57:46Z")

</div>

I can test the code in sandbox using a button on a page that calls the backend code that calls a remote rest service and loads images into the database. If i try launch it from the http function nothing happens (i get the successful response but the code doesnt actually run). I am not sure what to do since the code is all working and everything is published i have checked the database on live and all it good and have published the side again to ensure those scripts are updated.

Edit: confirmed it is the http function - if i use the button on the live site and use that to call the code from live it works. I need to have this automated to can someone help me understand why the http function isnt working?

by the way the response is fine when calling the function - is there a way i can access some logs to see what is going un?

---

<div class="post-metadata">

**Author:** ![waynetheron](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/waynetheron/32/9009_2.png) [@waynetheron](https://forum.wixstudio.com/u/waynetheron)\
**Post date:** [May 13, 2019, 8:25am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098/2 "2019-05-13T08:25:25Z")

</div>

here is the http function code (i have 3 other functions and they all working okay

export function get\_chartdata(request) {

**let** options = {  
“headers”: { “Content-Type”: “application/json” }  
};

```
options.body = { "status": "ok" } 

pullecondata(); 

```

**return** ok(options);

};

---

<div class="post-metadata">

**Author:** ![waynetheron](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/waynetheron/32/9009_2.png) [@waynetheron](https://forum.wixstudio.com/u/waynetheron)\
**Post date:** [May 13, 2019, 8:28am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098/3 "2019-05-13T08:28:36Z")

</div>

here is the main function that does the work

export function pullecondata () {

//get url template  
wixData.query(“charturl”)  
.find()  
.then( (results) =\> {  
**var** item = results.items[0]  
**let** urltemplate = item.urltemplate

//iterate rows to populate charts  
wixData.query(“econdata”)  
.find()  
.then( (econresults) =\> {

```
        console.log(econresults.items.length) 

        econresults.items.forEach( **function** (element) { 

            console.log(element.release) 

```

**let** newitem = element  
**return** fetch(newitem.data, {“method”: “get”})  
.then( response =\> response.json())  
.then(json =\> {  
**var** labels =   
**var** vals =

//access json data for chart from rest service payload  
**for(let** i **in** json.dataset.data) {

**var** dt = **new** Date(json.dataset.data[i][0])  
labels.push(dt.toLocaleDateString())  
vals.push(json.dataset.data[i][1])

```
                } 

```

//remove some records not needed  
vals.pop()  
vals.pop()  
vals.pop()  
labels.pop()  
labels.pop()  
labels.pop()

//reorder for date  
vals = vals.reverse()  
labels = labels.reverse()

//build array list of labels and data  
**var** quotedAndCommaSeparated = “'” + labels.join(“‘,’”) + “'”  
**var** u = urltemplate.replace(‘£’, quotedAndCommaSeparated )  
**var** g = u.replace( ‘@’,vals.join())

```
                newitem.chart = g 
                console.log("saving") 
                wixData.save("econdata", newitem); 

            }) 

        }) 

   }) 

}) 

```

}

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [May 13, 2019, 8:32am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098/4 "2019-05-13T08:32:30Z")

</div>

Make sure you publish your site or the HTTP endpoints won’t be accessible. See the article [Corvid: Exposing a Site API with HTTP Functions](https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions) for more information on HTTP functions. You can also use the [MyApi and MyApiClient](https://www.wix.com/code/home/forum/wix-tips-and-updates/example-myapi-and-myapiclient) example.

---

<div class="post-metadata">

**Author:** ![waynetheron](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/waynetheron/32/9009_2.png) [@waynetheron](https://forum.wixstudio.com/u/waynetheron)\
**Post date:** [May 13, 2019, 8:39am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098/5 "2019-05-13T08:39:31Z")

</div>

hi Yisrael

All is published several times and i have ensured the database collections are also in sync. The http function is returning a status okay but the code never runs. is it perhaps a permission issue i need to be aware of?

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [May 13, 2019, 9:19am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098/6 "2019-05-13T09:19:20Z")

</div>

@waynetheron Hard to say what’s not working. It might be an issue of database permissions. Since this is backend code, you can use the [suppressAuth option](https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions) to eliminate that issue.

---

<div class="post-metadata">

**Author:** ![waynetheron](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/waynetheron/32/9009_2.png) [@waynetheron](https://forum.wixstudio.com/u/waynetheron)\
**Post date:** [May 13, 2019, 9:39am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098/7 "2019-05-13T09:39:28Z")

</div>

@yisrael-wix

Thank you Yisrael - suppressing auth worked 🙂 happy days

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [May 13, 2019, 11:07am UTC](https://forum.wixstudio.com/t/wix-http-functions-not-working-but-code-is-working/20098/8 "2019-05-13T11:07:21Z")

</div>

@waynetheron Wow! You mean I did something today? 🍻🎉
