How to get an API to return a single number value

Hello,

I’ve been trying for the past couple of days to get a simple API function to work to no avail. I’m basically trying to rebuild what I have on Bubble in Wappler so these are API calls / formats that are already functioning in Bubble.

I’m trying to call an API from my backend (Xano) that is supposed to return a single number. The API is supposed to take in a business_id and then return the number of active projects associated with that business. The basic setup is below where I set the business_id in the input to a global session variable.

I’ve tried different combinations where I put the business_id input variable under GET, PARAM, and SESSION groups both at the global level and also specific to the API but to no avail.

When I Fetch Schema to test the API (see below), it always generates one of two results: 2 or 4, depending on which business_id value I put in the SESSION variable. However, in the snapshot example, it’s supposed to return 1 not 4. I’ve double-checked Xano as well as Bubble and both return a value of 1 so I can’t figure out why Wappler is returning 4.

When I checked the error status and message generated, this is what I saw: "401: Unauthorized [object Object]. I’m confused because this API works on Xano and Bubble.

To summarize, my questions are:

  1. What am I missing and what’s making Wappler not return the correct number for the API call? Why does it keep returning 2 or 4 all the time but not the correct number.
  2. What does the 401 error message mean? I’m using the authentication token and have setup it up correctly. In fact, I call the auth token the same way for my login flow using the same global variable I’m calling to authenticate this API call.

Thanks for your assistance.

Never used Xano before but i see one obvious issue
image

Thank you for the response. I’m still seeing the same problem.

I might be wrong but “input data” with GET method seems off to me… Try using Query params fields?

What happens if you hard code your session variable in? Ie for testing just use the id and not session data?

it still results in the same error

This approach seems to be working. When I fetch the API, it returns ‘1’, which is the correct response.

However, when I try to call the API in the app page, I don’t see a place where I can dynamically point the PARAM variable. There is no option for me to connect the PARAM variable to a business id. Am I missing something?:

How do I set the PARAM to a variable with dynamic values?

(PS: I tried making the param a global variable but it only seems to work if I define the “business_id” inside the API itself versus in the global variable).

Why would you need to use PARAM here? Use GET variables and they will appear under Input Parameters section there.

1 Like

Thank you, @Teodor . I used the GET variables and the option to input the dynamic varable (business_id) showed up so that was great. I now have the issue of referencing the value generated by this API. I want to display the API response (a number). Even though Fetching API showed me that the response should have a $value field that is a number, I can’t find that value field when I try to call it from the frontend.

Instead, I can only select the Type field from the frontend which doesn’t give me anything. I don’t see the $value field and type now shows up as being a text when the API returned it as a number as you can see in the previous image.

So naturally, I get a a 401 error message like I did in the first post.

Any assistance / direction will be appreciated.