API Connector to a local API

I have an API running locally (havent set it up on AWS yet) and I want to test it with my bubble app. I have downloaded API Connector and done GET but when I initialise the call it says The host is not valid. Can someone help please?

Not 100% sure on this one, but if it is running locally, it is not on the internet for your bubble app to interact with.

My guess would be that the API connector is trying to connect to that address on the cluster that your app is hosted on, not your local machine. For instance, looks different for me than it does for you.

If you are interested, you can still setup your API locally but you need to portforward your router and connect through the external IP

Yeah good point, is there any documentation/advice on how to port forward the router and connect through the external IP?

You will need to use your own IP (not local one) to access to your local API from Bubble. Don’t forget to check your firewall.

If you don’t know your IP, you can find site that give it (https://www.whatismyip.com/). If you are using ipv6, you need to put the value between []

1 Like

As far as a resource goes for port forwarding, I searched for articles around hosting a server / web service on your local machine.

Hope this article helps: How to convert your laptop/desktop into a server and host internet accessible website on it: Part 2

1 Like

Ah thanks a lot! So am I right in thinking that I would need to do http://[ipaddress]/apiname?? Or is it something else?

I think it would be [ipaddress]:port


[] only needed with ipv6. ipv4 can be set without them

sorry, when you say port would it still be :5000/apiname as thats what it is on local host? I’ve not done this before so really need it dumbing down

It would depend on the specifics of the configuration of your API. But I would think that just the port would be sufficient.

hmm, no luck doing [ipaddress]:5000/apiendpointname

I now have it working, but when I call it I get the message The API call returns a non-object and you picked JSON. Please check.
I’m outputting JSON and even shows as JSON on Postman?

Do you have a response header that say you are sending back a JSON?

No not sure what this means really

Where do I put the header?

In your server, you may need to provide a Content-type header too so Bubble know which payload type is back and parse it. this is a setting on your local server

Ok I’ve done that. Still no luck

Really just can’t work out why this is happening, in postman JSON is returned, via the browser its in JSON as well.

Bubble’s servers aren’t running on your device, which is why. localhost won’t work.

Instead of opening a port of your device to the public for anyone to connect to and thereby hack you device, just. use POSTMAN.

Postman is an API design tool that allows you to create a mock server for your API, on their servers, in an extremely easy way. https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/mocking-with-examples/

1 Like