# Count Words of text returned from an API

**URL:** <https://forum.bubble.io/t/count-words-of-text-returned-from-an-api/239234>\
**Category:** APIs\
**Created:** [December 30, 2022, 9:20pm UTC](https://forum.bubble.io/t/count-words-of-text-returned-from-an-api/239234 "2022-12-30T21:20:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashley.russell77](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@ashley.russell77](https://forum.bubble.io/u/ashley.russell77)\
**Post date:** [December 30, 2022, 9:20pm UTC](https://forum.bubble.io/t/count-words-of-text-returned-from-an-api/239234/1 "2022-12-30T21:20:36Z")

</div>

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](http://forum.bubble.io/t/new-plugin-thecountable-now-free/32777/82)

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.

---

<div class="post-metadata">

**Author:** ![tylerboodman](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/tylerboodman/32/242142_2.png) [@tylerboodman](https://forum.bubble.io/u/tylerboodman)\
**Post date:** [December 30, 2022, 9:32pm UTC](https://forum.bubble.io/t/count-words-of-text-returned-from-an-api/239234/2 "2022-12-30T21:32:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ashley.russell77](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@ashley.russell77](https://forum.bubble.io/u/ashley.russell77)\
**Post date:** [December 30, 2022, 9:46pm UTC](https://forum.bubble.io/t/count-words-of-text-returned-from-an-api/239234/3 "2022-12-30T21:46:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tylerboodman](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/tylerboodman/32/242142_2.png) [@tylerboodman](https://forum.bubble.io/u/tylerboodman)\
**Post date:** [December 30, 2022, 9:49pm UTC](https://forum.bubble.io/t/count-words-of-text-returned-from-an-api/239234/4 "2022-12-30T21:49:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ashley.russell77](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@ashley.russell77](https://forum.bubble.io/u/ashley.russell77)\
**Post date:** [December 30, 2022, 10:02pm UTC](https://forum.bubble.io/t/count-words-of-text-returned-from-an-api/239234/5 "2022-12-30T22:02:38Z")

</div>

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