# One netlify function does not work - Unexpected end of JSON input - Function not found

**URL:** <https://answers.netlify.com/t/one-netlify-function-does-not-work-unexpected-end-of-json-input-function-not-found/108482>\
**Category:** Support\
**Tags:** lambda-functions, create-react-app, netlify-newbie\
**Created:** [December 12, 2023, 4:45pm UTC](https://answers.netlify.com/t/one-netlify-function-does-not-work-unexpected-end-of-json-input-function-not-found/108482 "2023-12-12T16:45:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Armd](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/armd/32/57202_2.png) [@Armd](https://answers.netlify.com/u/Armd)\
**Post date:** [December 12, 2023, 4:45pm UTC](https://answers.netlify.com/t/one-netlify-function-does-not-work-unexpected-end-of-json-input-function-not-found/108482/1 "2023-12-12T16:45:04Z")

</div>

Hello,

I have been working on a react project with some netlify functions which works except one function that is not found despite beeing deployed to netlify, it does not work locally and when deployed. If you require the site URL let me know.

this is the function that calls the netlify function:

```auto
 let result = await fetch('/api/add-to-cart', 
    {
      method: 'post',
      body: JSON.stringify({ cartId: localCartData.cartId, variantId: id, quantity: quantity })
    });

```

A note is that the function above works on postman when using the direct url to shopify storefront API using a graphql body.

this is the function that is deployed on netlify, a note is that the rest of the functions works except this one. I have been trying to solve this matter for some time now but i have not found any solutions so far.

```auto
 const data = await sendShopifyStorefrontRequest({
    query: `
      mutation AddToCart($cartId: ID!, $variantId: ID!) {
        cartLinesAdd(cartId: $cartId, lines: [{ quantity: $quantity, merchandiseId: $variantId}]) {
          cart {
            lines(first: 100) {
              edges {
                node {
                  id
                  quantity
                  merchandise {
                    ... on ProductVariant {
                      product {
                        title
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    `,
    variables: { cartId, variantId, quantity },
  });

  return {
    statusCode: 200,
    body: JSON.stringify(data),
    headers: {
      "Access-Control-Allow-Origin": '*', // Allow from anywhere 
      "Access-Control-Allow-Methods": "*",
      "Access-Control-Allow-Headers": "*",
    }
  };
}

```

netlify toml:

```auto

[functions]
node_bundler = "esbuild"

[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200

[build]
functions = "netlify/functions"

```

```auto
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Runtime.handler (/var/task/netlify/functions/add-to-cart.js:5984:48)
    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)

```

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [December 17, 2023, 5:27pm UTC](https://answers.netlify.com/t/one-netlify-function-does-not-work-unexpected-end-of-json-input-function-not-found/108482/2 "2023-12-17T17:27:42Z")

</div>

> [@Armd](#):
>
> If you require the site URL let me know.

That and the steps to reproduce this issue would be helpful.

---

<div class="post-metadata">

**Author:** ![Armd](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/armd/32/57202_2.png) [@Armd](https://answers.netlify.com/u/Armd)\
**Post date:** [February 2, 2024, 12:28pm UTC](https://answers.netlify.com/t/one-netlify-function-does-not-work-unexpected-end-of-json-input-function-not-found/108482/3 "2024-02-02T12:28:27Z")

</div>

Hello, sorry for the late reply.

I have resolved this matter, i used the api calls directly inside the React component instead of making a netlify function, just for this particular function.
