Hey there, fellow code wranglers! Ready to dive into the world of Process Street API integration? Buckle up, because we're about to embark on a journey that'll supercharge your workflow automation game. This guide will walk you through creating a slick JavaScript integration that'll have you manipulating workflows and tasks like a pro.
Before we jump in, make sure you've got:
First things first, let's get our project off the ground:
mkdir process-street-integration cd process-street-integration npm init -y npm install axios dotenv
Create a .env
file for your API key:
PROCESS_STREET_API_KEY=your_api_key_here
Let's set up our API client with authentication:
require('dotenv').config(); const axios = require('axios'); const client = axios.create({ baseURL: 'https://api.process.st/api/v1', headers: { Authorization: `Bearer ${process.env.PROCESS_STREET_API_KEY}`, 'Content-Type': 'application/json' } });
Now, let's fetch some workflows:
async function getWorkflows() { try { const response = await client.get('/workflows'); console.log(response.data); } catch (error) { console.error('Error fetching workflows:', error.response.data); } } getWorkflows();
Creating a task? Easy peasy:
async function createTask(workflowRunId, taskId) { try { const response = await client.post(`/workflow-runs/${workflowRunId}/tasks/${taskId}/complete`); console.log('Task completed:', response.data); } catch (error) { console.error('Error creating task:', error.response.data); } }
Process Street's API speaks JSON. Here's how to listen:
async function handleApiResponse(apiCall) { try { const response = await apiCall(); return response.data; } catch (error) { if (error.response) { console.error('API Error:', error.response.status, error.response.data); } else { console.error('Network Error:', error.message); } throw error; } }
Want to paginate through results? We've got you covered:
async function getAllWorkflows() { let page = 1; let allWorkflows = []; while (true) { const response = await client.get('/workflows', { params: { page, limit: 100 } }); allWorkflows = allWorkflows.concat(response.data); if (response.data.length < 100) break; page++; } return allWorkflows; }
Stay in the loop with real-time updates:
const express = require('express'); const app = express(); app.post('/webhook', express.json(), (req, res) => { console.log('Webhook received:', req.body); res.sendStatus(200); }); app.listen(3000, () => console.log('Webhook server running on port 3000'));
Don't forget to test! Here's a quick Jest example:
jest.mock('axios'); test('getWorkflows fetches workflows successfully', async () => { axios.get.mockResolvedValue({ data: [{ id: 1, name: 'Test Workflow' }] }); const workflows = await getWorkflows(); expect(workflows).toHaveLength(1); expect(workflows[0].name).toBe('Test Workflow'); });
When you're ready to ship:
And there you have it! You're now armed with the knowledge to build a robust Process Street API integration. Remember, the API is your oyster – get creative and build something awesome!
For more details, check out the Process Street API docs. Happy coding, and may your workflows always run smoothly!
Find the complete example code for this integration on GitHub.