Hey there, fellow developer! Ready to supercharge your workflow with Pipefy's API? In this guide, we'll walk through building a Ruby integration that'll have you managing pipes and cards like a pro. Let's dive in!
Before we get our hands dirty, make sure you've got:
Got all that? Great! Let's move on.
First things first, let's create a new Ruby project and grab the gems we need:
mkdir pipefy_integration cd pipefy_integration bundle init
Now, add these lines to your Gemfile:
gem 'httparty' gem 'dotenv'
Run bundle install
, and we're off to the races!
Pipefy uses token-based authentication. Create a .env
file in your project root and add your API token:
PIPEFY_API_TOKEN=your_api_token_here
Now, let's set up our HTTP headers:
require 'httparty' require 'dotenv/load' headers = { 'Authorization' => "Bearer #{ENV['PIPEFY_API_TOKEN']}", 'Content-Type' => 'application/json' }
Time to make our first API call! Let's fetch some organization data:
response = HTTParty.get('https://api.pipefy.com/graphql', headers: headers, body: { query: '{ me { id name } }' }.to_json ) puts response.parsed_response
If all goes well, you should see your Pipefy user info. Cool, right?
Now for the fun part - let's create, read, update, and delete pipes!
query = <<~GRAPHQL mutation { createPipe(input: { name: "My Awesome Pipe", organization_id: 12345 }) { pipe { id name } } } GRAPHQL response = HTTParty.post('https://api.pipefy.com/graphql', headers: headers, body: { query: query }.to_json ) puts response.parsed_response
query = <<~GRAPHQL { pipe(id: 12345) { name phases { name } } } GRAPHQL response = HTTParty.post('https://api.pipefy.com/graphql', headers: headers, body: { query: query }.to_json ) puts response.parsed_response
Updating and deleting follow a similar pattern. Easy peasy!
Cards are the heart of Pipefy. Let's create one and move it around:
query = <<~GRAPHQL mutation { createCard(input: { pipe_id: 12345, title: "New task", fields_attributes: [ { field_id: "title", field_value: "Do the thing" } ] }) { card { id title } } } GRAPHQL response = HTTParty.post('https://api.pipefy.com/graphql', headers: headers, body: { query: query }.to_json ) puts response.parsed_response
query = <<~GRAPHQL mutation { moveCardToPhase(input: { card_id: 67890, destination_phase_id: 54321 }) { card { id title phase { name } } } } GRAPHQL response = HTTParty.post('https://api.pipefy.com/graphql', headers: headers, body: { query: query }.to_json ) puts response.parsed_response
Always wrap your API calls in begin/rescue blocks to handle errors gracefully:
begin response = HTTParty.post('https://api.pipefy.com/graphql', headers: headers, body: { query: query }.to_json ) if response.success? puts response.parsed_response else puts "Error: #{response.code} - #{response.message}" end rescue => e puts "An error occurred: #{e.message}" end
And don't forget about rate limits! Pipefy has a limit of 30 requests per minute, so space out your calls if you're doing bulk operations.
And there you have it! You're now equipped to build awesome Pipefy integrations with Ruby. Remember, this is just scratching the surface - there's so much more you can do with webhooks, batch operations, and more.
Keep exploring, keep coding, and most importantly, keep automating those workflows! Happy coding!