Session variables to store API login key

Yah I figured I needed to use this to store the users token session ID. I am speaking about my API access key provided by my backend team. I tried to assign it to the session manager but there is no way to input the value of the key. So far the only way I have been able to accomplish this is to use a variable and place that variable on each page where an API is used.

I you know of a better or more efficient way I am all eyes and ears. LOL.

Oh, yes, if it’s a static key by all means put on your main.ejs or something

You can then access such variable from any page

great… So that is what I thought to do. Buddy, thanks for the help!.

when applying the success to the api form and storing it in the session manager, what action do I apply? how do I apply the action of placing the token received as the action to accomplish?

this is what I did just guessing, I applied upon success to the session manager and the action is grab form data and apply.

Screen Shot 2023-01-12 at 7.30.15 PM

You’re welcome!

Dynamic Event:

Click the Play button:
Play button

And you should see “token” in the dropdown near where you can type the variable content, on that window (this “token” you’ve created previously when defining the schema of the session manager)

Edit: I don’t see “token” in your fmLogin.data, it should’ve been there I guess

yah I see token; did I apply the correct action?

The field Value, does .type contains the token? Because, according to earlier screenshots, I was expecting something ending in .token

Go to the form, click Define Schema, and ensure the schema is right, and hit Save

got it. For me to define the schema I need to replace the value of user and pwdhash with a current user and password. Man I am so close to getting this to work. Thanks for your help my friend!

1 Like

I didn’t understand anything you said but it’s ok :smiley:

This is the screenshot I was referring to, you can see it has a “token” variable, so I was expecting you to be able to select it:

I’m now going to sleep, so good night!

thanks again…

@Apple

Hey I am sure you are asleep now but I am hoping you have one last answer for me.

This is the most frustrating part I have experience. When testing the API through the workflow API action, I have success and it returns the info that I showed you in that screen shot. Now here is the really frustrating part. I am inputting the exact same info in the API form (now remember, I have already hit the API and the key is correct). when hitting the define schema button this is the error I receive back.

why in the world would it send me back this error, but not show an error in the API workflow API action? I even inputed the API key directly in the header and bypassed the variable and I still get that error.

Man this is frustrating.

it also returned this under source;

That screenshot doesn’t show the fields for the username and password, hence you can’t get a proper response as you’re trying to login with empty data. I don’t know how to fix it on top of my head. Because the API form is not so used compared to the Server Action (back-end) API Action, don’t discard the possibility of a Wappler bug

yah I think it is a bug… see the screen shot. Man this is a bummer…

You can workaround by pasting a good response clicking the Play button I believe, so the schema is inferred from what you pasted instead of Wappler itself doing the API request. You can use tools like Postman or Insomnia to perform API requests and grab the response

Ok so I can paste the response below in the Define schema. I have the response received via postman. Let me try that out.

allright! that worked… I was able to assign the token to the session manager!.. sweet success… LOL.

Ok buddy, now I have one more question for you, is there any documentation for upon success I would like to redirect to the same home landing page but have an avatar icon appear? I just need to understand redirection upon success and the process behind it as to how Wappler does it.

Thanks again for your help!

No problem, buddy! You need to add a “browser” component to your main.ejs, you’ll have access to the Redirect action when you do the on form success stuff

great I have that already set up. Ill try to work through it might hit you up if I have any further questions. Just FYI, the API form has a lot of issues. I am sending in a bug report. The define schema does not work with out forcing it like you stated. The second issue is that the GET command does not show up as a method, when selecting POST the method shows up. When I coded GET in its place, it took it but when I processed the form, its send it not as an GET but as an option.

when the form is submitted this is the return the server give my backend team;
INFO:
INFO:
70.171.193.203:56388
“GET /showsessions HTTP/1.1” 200 OK
96.245.129.93:64100 -
“OPTIONS /userlogin?user=craig&pwdhash=123&user=craig&pwahash=123&= HTTP/1.1” 405 Method Not Allowed

Hi,

I haven’t checked the video as I’m not home, but the last issue regarding you seeing “OPTIONS”, this is a CORS issue, your back-end team needs to allow your front-end to connect to it and that’s called CORS. If you inspect your browser’s developer console you’ll see a CORS warning there once you perform the API request

Yah, I wish it was that simple. Its a CORS method issue. It is looking for a GET and its receiving an OPITIONS. check out this article;

That is where the issue lies, there is a bug within the Method section of the API FORM. When I select Post the method is placed. However when I select GET it is gone. I have written it back in and it still has the issue of replacing it as OPTION

I’ve now seen the video. Regarding the GET method disappearing, that’s ok because GET is the default according to the HTML standard:

So, if “method” disappears, it’s assumed to be a GET one.

Browsers will always make an OPTIONS request before making a GET to third-party address, that’s not your issue, that’s an issue your back-end team must fix by returning the appropriate CORS header(s). Once that’s fixed, the browser will perform the GET request normally after the (first) OPTIONS request