# Javascript Action Question

**URL:** <https://community.weweb.io/t/javascript-action-question/1533>\
**Category:** How do I?\
**Created:** [December 1, 2022, 6:28pm UTC](https://community.weweb.io/t/javascript-action-question/1533 "2022-12-01T18:28:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [December 1, 2022, 6:28pm UTC](https://community.weweb.io/t/javascript-action-question/1533/1 "2022-12-01T18:28:55Z")

</div>

I’m trying to integrate the Chargebee portal into my site. It’s pretty straightforward as you just have to include a script in your header, and then add a button that when clicked does SSO into their portal. I included the header script on the page, and also tried globally.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/b/b80fba3c165cd4ee382a99447d1baa3c96219b99.png)

One thing I’m not sure about, when is how to properly integrate the Portal Button Code section,

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/b/bff9cfe50f69f4d62cffc47e9c8c8d0eedfce3e6.png)

I tried using Custom HTML to paste this code in, but nothing is happening when I click the link. Any idea on how to properly implement this line of code in Weweb?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/c/cf06b390c1776593e70ededc8e6927500608ab8e.png)

---

<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:** [December 1, 2022, 7:00pm UTC](https://community.weweb.io/t/javascript-action-question/1533/2 "2022-12-01T19:00:09Z")

</div>

Code added with global settings or page settings is not loaded in the editor but it will load in the live app. Probably this is the reason your link it’s not working.

If you want it to load in the editor you can try inserting the script into an html element and see if it works, see [here as well](https://community.weweb.io/t/how-to-integrate-highcharts-library/965/4).

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [December 2, 2022, 4:58am UTC](https://community.weweb.io/t/javascript-action-question/1533/3 "2022-12-02T04:58:28Z")

</div>

Yeah I tried in my published application, it just opens a new tab straight back to weweb. In terms of custom module, haven’t really built anything like that, big learning curve, but will look into it.

---

<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:** [December 2, 2022, 7:54am UTC](https://community.weweb.io/t/javascript-action-question/1533/4 "2022-12-02T07:54:02Z")

</div>

Maybe the problem is that the library is scanning the page for the link but it’s not there yet.

Check the reference of the library, maybe there is a method to initiate the scanning again.

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [December 3, 2022, 12:15am UTC](https://community.weweb.io/t/javascript-action-question/1533/5 "2022-12-03T00:15:46Z")

</div>

I think you may be right, it looks like i need to initiate the session, right now it’s prob just kicking back nothing.

I need to make this REST API call in WeWeb, any idea on how to translate what’s shown here into a REST request? I can’t seem to get the AUTH working. (Keys are just dummy)

> **[Portal sessions
            
            | Chargebee API documentation](https://apidocs.chargebee.com/docs/api/portal_sessions?prod_cat_ver=1#create_a_portal_session)**
>
> This API enables customers to manage their billings and accounts. The Portal Sessions API contains operations to manage portal access for customers.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/c/c2faaca7894610356368d63c08649458e150f30a.png)

---

<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:** [December 5, 2022, 7:56am UTC](https://community.weweb.io/t/javascript-action-question/1533/6 "2022-12-05T07:56:25Z")

</div>

what did you try?

It should be basic access authorization with just username, so you need a `Authorization` header with value `Basic yourapikey:`

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [December 5, 2022, 4:22pm UTC](https://community.weweb.io/t/javascript-action-question/1533/7 "2022-12-05T16:22:09Z")

</div>

Yep that is exactly what I’m trying, not entirely sure what I’m doing wrong. I’ve confirmed this same works when sending through some CURL

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/d/d87bc18582352940ec3c909eb369ff78b8606ed2.png)  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/d/daafc861645f504216afbe9a38539435298b5d28.png)

message: “Sorry,authentication failed. The authorization header for basic authentication not present in request”

api\_error\_code: “api\_authentication\_failed”

error\_code: “api\_authentication\_required”

error\_msg: “Sorry,authentication failed. The authorization header for basic authentication not present in request”

---

<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:** [December 5, 2022, 5:45pm UTC](https://community.weweb.io/t/javascript-action-question/1533/8 "2022-12-05T17:45:29Z")

</div>

The header name should be `Authorization`.

In your screenshot you have “authentication” that’s why the error says it’s not present.

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [December 5, 2022, 7:41pm UTC](https://community.weweb.io/t/javascript-action-question/1533/9 "2022-12-05T19:41:26Z")

</div>

Ah good catch, OK so fixed that, but what is odd is that I’m getting API authentication failed ‘Invalid API Key’ - But what is odd is that I’m using that same key in Insomnia to test the API, and it’s working just fine. Is there any formatting that needs to be done on the value outside of **Basic key:**

I also noticed these different content types, would this just be default in most cases?

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/a/a199248c4d240cec4d1bcfa6604c8d4318bfe681.png)

---

<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:** [December 6, 2022, 8:35am UTC](https://community.weweb.io/t/javascript-action-question/1533/10 "2022-12-06T08:35:38Z")

</div>

I guess you should find all the details in the documentation of the API you are calling.  
Do you have a way to export the details of the request from Insomnia?

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [December 6, 2022, 4:45pm UTC](https://community.weweb.io/t/javascript-action-question/1533/11 "2022-12-06T16:45:14Z")

</div>

Good news, I was able to get Authentication working. What I found was that it appears Insomnia is encoding the API key to something else before sending, when I use that encoded key which Insomnia API spits out in Weweb, it works.

The only thing I’m trying to figure out at this point is passing parameters which doesn’t appear to work. I’m trying to pass this -d customer[id] value, but doesn’t appear to be taking it.

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/e/e3dacacc02dbc4a1b90abe4f295e9bfe1bf6891b.png)

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/2/23f3318bca6b2478a58d0c76fe05b3e1686291ad.png)

---

<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:** [December 6, 2022, 5:02pm UTC](https://community.weweb.io/t/javascript-action-question/1533/12 "2022-12-06T17:02:54Z")

</div>

`-d` is part of the curl command, not the key value

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [December 6, 2022, 5:06pm UTC](https://community.weweb.io/t/javascript-action-question/1533/13 "2022-12-06T17:06:56Z")

</div>

Remove it and it’s working, thank you so much!!!
