# Using fetch - not working :(

**URL:** <https://forum.wixstudio.com/t/using-fetch-not-working/37345>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [October 18, 2017, 2:15pm UTC](https://forum.wixstudio.com/t/using-fetch-not-working/37345 "2017-10-18T14:15:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aitor-conde](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/aitor-conde/32/957_2.png) [@aitor-conde](https://forum.wixstudio.com/u/aitor-conde)\
**Post date:** [October 18, 2017, 2:15pm UTC](https://forum.wixstudio.com/t/using-fetch-not-working/37345/1 "2017-10-18T14:15:36Z")

</div>

Hi guys,

First of all, thanks for this amazing product, what you’ve done lately opening wix so you can add back end functionality is really good.

I’m trying to use the wix-fetch api but I’m not getting any response back once the fetch is sent. I’m debugging it using console.log, the last console.log triggered is this: console.log(headers);  
I’ve obfuscated the API keys for obvious reasons. Please find snippet below:

import {fetch} from ‘wix-fetch’;  
const CLIENT\_ID = “blablabla”;  
const CLIENT\_SECRET = “blebleble”;  
export function addToEmailList (address) {  
console.log(“back end function raised!”);  
var data={  
grant\_type:‘client\_credentials’,  
client\_id: CLIENT\_ID,  
client\_secret: CLIENT\_SECRET  
};  
console.log(data);  
console.log(JSON.stringify(data));  
var headers = { ‘Content-Type’:‘application/json’, ‘Content-Length’: JSON.stringify(data).length.toString() };

```
console.log(headers); 
fetch("https://api.sendpulse.com/oauth/access_token", { 
         method: 'POST',              
         headers: headers, 
         body: JSON.stringify(data) }) 
 .then(response => { 
 	console.log("1"); 
	return response.json() 
		.then(data => { 
	      if (response.ok) { 
	      	console.log("2"); 
	        return data; 
	      } else { 
	      	console.log("3"); 
	        return Promise.reject({status: response.status, data}); 
	      } 
}); 

```

})  
.then(result =\> console.log(‘success:’, result))  
.catch(error =\> console.log(‘error:’, error));  
}

---

<div class="post-metadata">

**Author:** ![sam-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sam-wix/32/683_2.png) [@sam-wix](https://forum.wixstudio.com/u/sam-wix)\
**Post date:** [October 18, 2017, 6:15pm UTC](https://forum.wixstudio.com/t/using-fetch-not-working/37345/2 "2017-10-18T18:15:53Z")

</div>

You would probably need a **return** before the **fetch** to see the console logs even if the fetch was working as explained here: [Velo: Testing and Troubleshooting Your Code | Help Center | Wix.com](https://support.wix.com/en/article/testing-and-debugging-code-with-developer-tools).

Also, have you tried opening the browser’s console (not the Wix Code console) to see if there are any errors logged there?

---

<div class="post-metadata">

**Author:** ![aitor-conde](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/aitor-conde/32/957_2.png) [@aitor-conde](https://forum.wixstudio.com/u/aitor-conde)\
**Post date:** [October 19, 2017, 2:09pm UTC](https://forum.wixstudio.com/t/using-fetch-not-working/37345/3 "2017-10-19T14:09:17Z")

</div>

Hi Sam,

All good now 🙂 It was as you said, the return missing.

Thanks a lot for your help!
