{urlload} Executes for Every Keystroke?

Hey Bill,

Cool use-case, I really enjoy seeing how people use Text Blaze to connect to the APIs of other services like this. I signed up for a free trial of Mem and used your snippet with my own API key -- I got the exact same behavior as you. There's two possible solutions to this, depending on what you're trying to do with this snippet:

  1. You could wrap your entire {urlload} command in a form toggle, so that it only actually makes the API call when you check the toggle box. That would let you fill out those form fields with information, and then check that box when you're ready to send the data to Mem.

{formtext: name=memtitle}
{formtext: name=memcontent}
{formtoggle: name=Ready to send info?; default=no}{urlload: https://api.mem.ai/v0/mems; done=(res) -> ["url": catch(fromJSON(res).url, "???")]; method=POST; headers=Authorization:ApiAccessToken: ..., Content-Type:application/json; body={"content": "# {=memtitle} (load)\n\n {=memcontent}"}}{endformtoggle}

  1. I noticed that you're using {urlload} instead of {urlsend}. {urlload} is primarily for retrieving information from APIs for use in your snippet, like these cool examples Dan made of retrieving data from Coda. As you've discovered, {urlload} can send information to APIs via the POST method (not just GET information), but {urlload} will also retriggers every time something about it changes - hence the behavior you're seeing. You could instead switch this to {urlsend} and remove the entire done: section from it, as I have below. Doing this will only result in the API call upon clicking the Text Blaze "insert" button.

{urlsend: https://api.mem.ai/v0/mems; method=POST; headers=Authorization:ApiAccessToken: ..., Content-Type:application/json; body={"content": "# {=memtitle} (load)\n\n {=memcontent}"}}

(note: make sure you still have your \ around the curly brackets in your body= portion to escape those special characters, that's not appearing in my preview above)

Using {urlload} does give you the callback information in your URL variable which is nice, so if that's an important part of your workflow then I'd go with wrapping it in the form toggle field in example #1. But both of those will stop the writing of data into Mem with every keystroke - whichever works best for your workflow would be up to you!

3 Likes