# I have a blocker using an external API

**URL:** <https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762>\
**Category:** How do I?\
**Created:** [July 7, 2022, 9:34am UTC](https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762 "2022-07-07T09:34:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walds](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/walds/32/389_2.png) [@Walds](https://community.weweb.io/u/Walds)\
**Post date:** [July 7, 2022, 9:34am UTC](https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762/1 "2022-07-07T09:34:57Z")

</div>

Hi, I’m trying to use Xendit for the payment process on my app. I’ve tried using custom JS and REST api request, both of which are to no avail. Whenever I use the REST api request, I always stumble upon a network error and when I try to make the request through a server, it returns an error 500.

As for the custom JS, I get blocked by the CORS policy.

Attached are some screenshots, JS code, and the api I’m trying to use:  
[https://developers.xendit.co/api-reference/?javascript#invoices](https://developers.xendit.co/api-reference/?javascript#invoices)

````auto
let body = 
{
    'external_id': 'testFee',
    'amount': 1000,
    'description': 'TestInvoiceFee',
    'customer': {
      'given_names': 'John Waldo',
      'surname': 'Magalona',
      'email': 'waldo.magalona@ahglab.com'
    },
    'customer_notification_preference': {
      'invoice_created': [
        'email'
      ],
      'invoice_reminder': [
        'email'
      ],
      'invoice_paid': [
        'email'
      ],
      'invoice_expired': [
        'email'
      ]
    },
    'success_redirect_url': window.location.href,
    'failure_redirect_url': window.location.href,
    'currency': 'PHP'
  };

fetch('https://api.xendit.co/v2/invoices', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Basic eG5kX2RldmVsb3BtZW50X0ZnenRmdlkwWFJONXFrZDBGRVhxcXJZZ0tWblgyUmJrbWt5Vlh2bjhrUW8zYklzcFVSTWllMjFxbTZCTlg9PTo='
  },
  body: JSON.stringify(body),
})
.then((response) => response.json())
.then((data) => {
  console.log('Success:', data);
})
.catch((error) => {
  console.error('Error:', error);
});```

![image|690x333](upload://t1a1aFJOYN1G5VHfOmEkG0X8GVm.jpeg)
![image|690x332](upload://AmfjjPdL2zF0JtYTwqv7rXIzV2y.jpeg)
![image|690x331](upload://3rgP3nqWt3H1Iz5yxfRzCddLClI.jpeg)
````

---

<div class="post-metadata">

**Author:** ![Walds](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/walds/32/389_2.png) [@Walds](https://community.weweb.io/u/Walds)\
**Post date:** [July 7, 2022, 9:35am UTC](https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762/2 "2022-07-07T09:35:32Z")

</div>

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/cb60a8e0a3fb9c97d8c92e486249d197c84cc47c.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/fed20d492a9463a7b46ac73b3c152eb9acb76e0a.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/181bb54117669d0e73f56d7426e463d62e452992.jpeg)

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [July 7, 2022, 10:13am UTC](https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762/3 "2022-07-07T10:13:02Z")

</div>

It looks like the API is meant to be used server side as they do not handle CORS.  
The api request maybe is failing because is not getting the right data. Are you adding the data as fields or query string?  
Also keep in mind that now we all know your auth password from the code you posted, and all the user of your app will know it as well. If this API is meant to be used server side you should consider to make this request on your backend.

---

<div class="post-metadata">

**Author:** ![Walds](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/walds/32/389_2.png) [@Walds](https://community.weweb.io/u/Walds)\
**Post date:** [July 7, 2022, 10:21am UTC](https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762/4 "2022-07-07T10:21:38Z")

</div>

Thank you @dorilama. I guess I might do it on my backend. I’ve already deleted that auth password on my Xendit account before posting this 😃

---

<div class="post-metadata">

**Author:** ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)\
**Post date:** [July 7, 2022, 10:16pm UTC](https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762/5 "2022-07-07T22:16:30Z")

</div>

Looking at your second screenshot, where you make a server-side request but still get a 500 error.

You unfolded the `response`. Can you also show what’s inside `data` of that response?

It might include more information about what is not working with the API call.

---

<div class="post-metadata">

**Author:** ![Walds](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/walds/32/389_2.png) [@Walds](https://community.weweb.io/u/Walds)\
**Post date:** [July 8, 2022, 7:08am UTC](https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762/6 "2022-07-08T07:08:23Z")

</div>

Hi @Joyce this is the content of data:

```auto
data
success: false
code: "INTERNAL_ERROR"

```

is it possible to install dependencies on our weweb app?

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [July 8, 2022, 10:39am UTC](https://community.weweb.io/t/i-have-a-blocker-using-an-external-api/762/7 "2022-07-08T10:39:25Z")

</div>

what about the data of the request? maybe it’s not the right data and the server does not handle the exception.
