# Unable to use javascript function fetch() on any endpoint

**URL:** <https://opendataforum.transport.nsw.gov.au/t/unable-to-use-javascript-function-fetch-on-any-endpoint/2611>\
**Category:** App development\
**Created:** [December 5, 2021, 11:01pm UTC](https://opendataforum.transport.nsw.gov.au/t/unable-to-use-javascript-function-fetch-on-any-endpoint/2611 "2021-12-05T23:01:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorenzoparas](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@lorenzoparas](https://opendataforum.transport.nsw.gov.au/u/lorenzoparas)\
**Post date:** [December 5, 2021, 11:01pm UTC](https://opendataforum.transport.nsw.gov.au/t/unable-to-use-javascript-function-fetch-on-any-endpoint/2611/1 "2021-12-05T23:01:04Z")

</div>

Hi, I’m trying to use the Carpark API to get the options of carparksp.

This is the code I have so far to fetch from the API:

```auto
async getCarparkOptions () {
        const result = await fetch('https://api.transport.nsw.gov.au/v1/carpark', {
            method: 'GET',
            headers: {
                'Content-Type': 'application-json',
                'Accept': 'application/json',
                'Authorization': 'apikey <key>locallocal',
                'Access-Control-Allow-Origin': 'true'
            }
        });
        return result;
    }

```

I get a “No Access-Control-Allow-Origin header” error, I’m guessing this is because my localhost:3000 is blocked from querying the API.

```auto
Access to fetch at 'https://api.transport.nsw.gov.au/v1/carpark' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

```

Any tips on how I could fetch from the API?

Thanks!

---

<div class="post-metadata">

**Author:** ![jayen](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jayen/32/208_2.png) [@jayen](https://opendataforum.transport.nsw.gov.au/u/jayen)\
**Post date:** [December 8, 2021, 4:00am UTC](https://opendataforum.transport.nsw.gov.au/t/unable-to-use-javascript-function-fetch-on-any-endpoint/2611/2 "2021-12-08T04:00:01Z")

</div>

you can’t do it from a browser. the major browsers check with the server if your site is allowed, and the server doesn’t allow any third-party sites.

you need a CORS proxy of some sort.
