Hi,
I need to pass a URL supplied by a User to the Bitly API. The Bitly API requires a fully formed URL which must include either “http://” or “https://”. What is the best practice for accepting the user’s input and determining whether I can pass it to the API as is or if I have to prepend “https://” to their input? Also, should I just pass “https://” to my workflow or is there a better method?
Thank you!
Roy
I don’t believe the entire endpoint string can be tokenized in the API Connector, can it?
Just tokenize the part of the endpoint url that needs customization.
Hi Keith,
Thank you for your quick reply but I’m not sure I understand your instructions.
If the user supplies “https://google.com”, then I can just use that string as the API parameter.
If the user supplies just “google.com’” or “www.google.com”, then I must prepend “https://” to that string as the API parameter.
What is the best way to accomplish this?
Roy
tokenize means:
https://[google.com]
the part between the brackets is tokenized and can be dynamic.
What you can do here is to set it like this: https://[google.com]
[] = inputs value find&replace: find: https:// and replace it with nothing, maybe another find&replace with http://
It sounded like you were trying to call an API endpoint completely dynamically (which I don’t think you can do).
If you have some parameter that’s supposed to be a fully-qualified URL, and you want to ensure the protocol part is there, take your input’s value, strip off any protocol using the regex value (^\w+:|^)\/\/
and pre-pend https://
. In Bubble, that expression looks like:
https://some_value:find and replace (replace that regex with nothing)
LIke so:
Any text field can do this (like your field for your parameter), but here’s an example in a standard text element:
Runtime: Works whether we leave off the protocol:
Specify the protocol correctly:
Or do something dumb:
You could further refine that if desired, but “how dumb do you expect your users to be?” is the question when doing stuff like this.