Forum Academy Marketplace Showcase Pricing Features

Count Words of text returned from an API

Hope someone can help with this problem I’ve been trying to solve all day.

I am trying to count the number of words returned from the text result of an external API. Then once the words are counted, I want to deduct that amount from the users “Credits”. I also use this text result from the API to update the state of a multi line input.

I’ve tried a couple of the word count plugins and have been close to solving this but neither of the plugins are working as required. An example is here: 🎛 New plugin - theCountable (now free) - #82 by ashley.russell77

My workflow would look something like this:

InputA > Sent to API > Result of API updates state of InputB > Words counted > Change thing (user credits) = credits - words counted.

The Words counted part is what I’m really stuck on right now.

Any suggestions would appreciated.

Make changes to [user], set credit field to This User's credits - Result of API's [text string]:split by (space):count?


Bro… I have no idea what that does but it worked! I can’t thank you enough.

What exactly is it the split thing doing in this expression?

1 Like

If you have a single text string AKA your paragraph the API returned, when you do :split by it turns it into a list of texts splitting by whatever character you want (in your case a space), now that it’s a list you can just count them by doing :count

If you needed to filter out “a” “to” “from” or whatever you don’t want to count as a word you can filter those out too before the count if needed

1 Like

All makes sense and so simple in the end, thank you again.

1 Like

Good simple answer - but if you need more sophistication, deal with unicode languages, emojis, deal with stray punctuation (eg don’t count hyphens, commas, etc as words), ie just want more than split by space - try

Full disclosure - it’s my commercial plugin but I just did some fixes on it to deal with emojis.

1 Like

Hey @lindsay_knowcode , just bought your plugin, it works great but what would make it perfect is if there was a way to use it in a workflow.

In my use case I have a rich text element. Text is added both through and API as well as through the user typing. I’m using your plugin to count the words that are generated so I can deduct that from their credits. I can separate the words coming in from the API by storing them in a state, but If I deduct the number of words in that state from their credits when the element value changes, it will deduct too much. By calculating it in a workflow I can calculate the number of words before it is added to the state.

Unless you know of a workaround?

@mark7 Thanks for the suggestion - I’ll add a server-side action - I think that is what you are requesting if I understand correctly?

1 Like

Thanks! Thats perfect. Either sever side or something in the regular workflows (maybe thats what server side is lol), either one would work

@mark7 Refresh your editor and pick up the new version of the plugin that has a server side action :slight_smile:

PERFECT!! Thanks so much. 5-Star Review coming in lol

1 Like

Knowcode… I get it


@lindsay_knowcode is it possible for you to add caracter count ? It could be very helpfull. In my case to calculate segments in sms like this : SMS Character Counter - Check your SMS character count and more!.
Do you think I can use it for this?

@Sarah_Esteve nice suggestion, I’ll add it in over the next few days. :slightly_smiling_face:

Good reference for the counting rules. :+1:t2:

1 Like

@Sarah_Esteve done - refresh your Editor to pickup the new plugin version. The documentation is currently minimal but hopefully enough to get you started :slight_smile: I’ll improve the documentation and examples later.

incredible! thank you so much I’ll test tonight !

hello @lindsay_knowcode ! I have this error throwing when the refering input of SMScount is empty. An idea to avoid it ? thx!

1 Like

Not sure - travelling today so can investigate tomorrow. What is the input text? It’s not empty by any chance?

Hello, np.

At loading page, the multiline input is empty yes

@Sarah_Esteve Fixed - thanks for reporting :slight_smile:
Refresh your Bubble Editor to pick up the new Plugin version.

1 Like