![]() ![]() After banging my head against a wall for a while, an experienced co-worker suggested that the character limit may be the reason (thank you, Arlemi Turpault, for that key insight!).īecause of the character limit, I reused this request multiple times. When I tried to send the content for 20 tweets to post to Slack in one shot, I continuously got an error message. I learned the hard way that Slack has a character limit on the body of a request. You can see that it sends only one tweet at time, called current_tweet, which is in the double curly braces to reference the variable named “current_tweet.” This is what the JSON body looks like for a POST request to a Slack webhook URL Solving a character-limit conundrum Here’s a picture of that JSON body below. Using Slack’s nifty Block Kit Builder tool, you can get quite a bit of flexibility and customization on how you want the message to go through. In the Body tab of the request, I formatted the content (the tweets) that I wanted sent over to Slack as JSON. After generating a webhook URL, I set up a POST request in Postman to send all tweets with the #PostmanGalaxy hashtag to a designated Slack channel that my team members were following. Slack makes it pretty easy to send things to a certain Slack channel using webhooks. Setting up Slack webhooks for notifications With all of our tweets and necessary information in place, it’s time to send these tweets somewhere the rest of our team can see them: a Slack channel. Sending a second request to Twitter to obtain more user information Upon a successful request, I used some JavaScript code in the Tests tab to match the newly acquired usernames with the corresponding author_ids to our saved data. I copied this request from the Twitter API v2 Postman Collection into my own folder and entered the environment variable as the query parameter value as shown below. Thankfully, the Twitter API has a “Users by ID” request that takes the string of IDs as a parameter. So I captured the IDs of the users in a comma separated string and saved it as an environment variable called allUserIdsString. And since we wanted to know who was using the #PostmanGalaxy hashtag, I needed to find a way to tie these author_ids to an actual Twitter handle that humans would understand. In fact, I couldn’t even tell you what mine is. Now I don’t know about you, but I don’t have other peoples’ Twitter ID numbers memorized. Because of the limited access inherent to the Standard product track, when I sent a search query for the string %23PostmanGalaxy to the Twitter API, it would return only the author_id, but not the user’s Twitter handle or Twitter name. Instead of doing a single search and getting everything I desired (username, user handle, date, source, body of tweet, etc.), I had to chain requests together using data from my initial search. This limited access meant I had to get creative with gathering all the necessary data. Instead of upgrading my product track, I thought to myself: “I’m a developer for the people! I’m going to find a way for even Standard track devs to do this.” I was also on a deadline and didn’t have time to apply and wait for my access to be upgraded. Since I used the basic “Standard” track, I was restricted from getting everything I needed in one shot. While the Twitter API can obtain a large amount of user data for a specific tweet, depending on which product track you are using, you may have some limited access to certain endpoints. It was that second part that was the challenge. Despite that, I found that I couldn’t do exactly what I wanted right out of the gate-which was to use the API to find all tweets containing a specific hashtag and get the user information for those tweets. ![]() Twitter has a vast, well-documented, and (dare I say) fun-to-use API. Look at all those kind tweets about Postman Galaxy! Twitter hashtag search bot for Postman Galaxy in action showing results in Slack The start of a new search bot Below is a result of the final integration in action. As a new Postman developer advocate, I was assigned to “figure out a way to have all the tweets with the #PostmanGalaxy hashtag automatically sent into a Slack channel.”Īfter brainstorming some different approaches, I was able to use a combination of the Twitter API, the Postman API, and Slack Incoming Webhooks to achieve exactly that. And more importantly, who was saying these things. When Postman recently hosted the Postman Galaxy virtual conference with attendees from around the world, I needed to find out what people were saying about the event. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |