# How to create API calls to external sources?

**URL:** <https://community.glideapps.com/t/how-to-create-api-calls-to-external-sources/46754>\
**Category:** Ask for Help\
**Created:** [August 15, 2022, 2:03am UTC](https://community.glideapps.com/t/how-to-create-api-calls-to-external-sources/46754 "2022-08-15T02:03:49Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [August 17, 2022, 5:00pm UTC](https://community.glideapps.com/t/how-to-create-api-calls-to-external-sources/46754/11 "2022-08-17T17:00:03Z")

</div>

Ok, I understand better. Here there are 2 points to keep in mind:

1)- This kind of syntax isn’t supported by JS plugin… I have lived this pain before 🙄

```auto
fetch("https://smartseoreport.com/api/v1/reports?url=https%3A%2F%exampledomain.com", {
      "method": "POST",
      "headers": {
            "Content-Type": "application/x-www-form-urlencoded",
            "Authorization": "Bearer abc123abc123abc123abc123abc123abc123abc123abc123"
      }
})
.then((res) => res.text())
.then(console.log.bind(console))
.catch(console.error.bind(console));

```

The right syntax must be something like:

```auto
var data= await fetch('https://smartseoreport.com/api/v1/reports?url=https%3A%2F%exampledomain.com', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'Bearer abc123abc123abc123abc123abc123abc123abc123abc123'
    },
});

const json = await data.text();
return json 

```

The reason? … Glide’s JS plugin doesn’t support the _Promise.prototype.then()_ method nor _console.log()_ function… I mean, these statements:

```auto
.then((res) => res.text())
.then(console.log.bind(console))
.catch(console.error.bind(console));

```

2)- If we run my JS code version in Glide, we receive an error message caused by a CORS policy so, we need to use a CORS proxy instead and change a bit your URL.

Your new URL is now:

> https://**[corsanywhere.herokuapp.com](http://corsanywhere.herokuapp.com)**/[https://smartseoreport.com/api/v1/reports?url=https%3A%2F%exampledomain.com](https://smartseoreport.com/api/v1/reports?url=https%3A%2F%25exampledomain.com)

where _[https://corsanywhere.herokuapp.com](https://corsanywhere.herokuapp.com)_ is our CORS proxy and the final JS code is this:

```auto
var data= await fetch('https://corsanywhere.herokuapp.com/https://smartseoreport.com/api/v1/reports?url=https%3A%2F%exampledomain.com', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'Bearer abc123abc123abc123abc123abc123abc123abc123abc123'
    },
});

const json = await data.text();
return json 

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/3/63f480979c7c9bc74f681c5f5d8a863f89cf242a.png)

Finally, we got the right results and enjoy the fireworks! 🎇 🎇

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/e/4e70325fc7a6d72b1eefb8fdf65778576141e065.png)

David time ago warned about the problem with [Bearer authorization](https://community.glideapps.com/t/post-to-api/38715/2) if the Fetch JSON plugin is used but now, I can confirm with your case that using the JavaScript plugin we can get good results working with Bearer authorization. It’s a great news @Tim_Gestels

BTW @globalint … I didn’t know your cool tool to create reports, it looks very useful! 💪

Saludos y feliz día!

---

_[View the full topic](https://community.glideapps.com/t/how-to-create-api-calls-to-external-sources/46754)._
