# wix fetch JSON array undefined

**URL:** <https://forum.wixstudio.com/t/wix-fetch-json-array-undefined/34048>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [October 12, 2022, 6:28am UTC](https://forum.wixstudio.com/t/wix-fetch-json-array-undefined/34048 "2022-10-12T06:28:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![william-anthony-pete](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/william-anthony-pete/32/35206_2.png) [@william-anthony-pete](https://forum.wixstudio.com/u/william-anthony-pete)\
**Post date:** [October 12, 2022, 6:28am UTC](https://forum.wixstudio.com/t/wix-fetch-json-array-undefined/34048/1 "2022-10-12T06:28:06Z")

</div>

Hi, i’m not a developer and have been trying to get this to work, but am having issues. I believe it is because i am not defining which item in the array to use, but not sure.  
I’m using wix fetch on the backend and receiving a httpResponse but can’t figure out how to replace a text element with the first JSON array object.

**backend:**  
_import wixSecretsBackend from ‘wix-secrets-backend’;_  
_import {fetch} from ‘wix-fetch’;_

_export async function getFlowersJson() {_  
_const secret = await_  
_let headers = {_  
_‘Authorization’: 'Basic ’ + Buffer.from(secret + “:” + pw).toString(‘base64’),_  
_‘Content-Type’: “application/json”,_  
_‘Access-Control-Allow-Origin’: "_"\*  
_};_  
_return_ [_fetch("[https://www.floristone](https://www.floristone)_](fetch("[https://www.floristone](https://www.floristone)) _. com/api/rest/flowershop/getproducts?category=md", {_  
_“method”: “GET”,_  
_“headers”: headers})_  
_.then((httpResponse) =\> {_  
_if(httpResponse.ok){_  
_return httpResponse.json();_  
_} else {_  
_return Promise.reject(“Fetch did no succeed”)_  
_}_  
_})_  
_}_

**Response data:**

![](https://us1.discourse-cdn.com/wix/original/3X/8/6/8610b7a418a64d09ac92b3d09c54453000d74eeb.jpeg)

**Front end:**  
trying to replace the “#textMain” element with the first array object description:

_import {getFlowersJson} from ‘backend/florist-one-api’;_

_export function button1\_click\_1(event) {_  
_getFlowersJson()_  
_.then((json) =\> {_  
_const products = Object.values(json)[0];_  
_console.log(json);_  
_$w(“#textMain”).text = String(products.description);_  
_} )_  
_.catch(err =\> {_  
_console.log(err);_  
_} )_  
_}_

Currently when i click the button, the text gets replaced with “Undefined”  
Any help would be appreciated.  
Thanks,  
Will

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [October 12, 2022, 4:34pm UTC](https://forum.wixstudio.com/t/wix-fetch-json-array-undefined/34048/2 "2022-10-12T16:34:32Z")

</div>

```javascript
//...
.then(result => {
      const PRODUCTS = result.PRODUCTS;
        if(PRODUCTS?.length){
		const FIRST_PRODUCT= products[0];
		$w("#textMain").text = FIRST_PRODUCT.DESCRIPTION;
	} else {
		//.....if there're no products, code...
	}
})
.catch(err => {/*code*/});

```
