Skip to content

Examples

Complete code examples for creating, starting, updating, and ending activities in curl, Python, Go, and JavaScript.

Info

All examples use the generic template. Replace hlk_YOUR_KEY with your integration key. See Templates for template-specific fields.

curl

Create activity
curl -X POST https://api.pushward.app/activities \
  -H "Authorization: Bearer hlk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"slug": "my-build", "name": "My Build"}'
Start activity
curl -X PATCH https://api.pushward.app/activity/my-build \
  -H "Authorization: Bearer hlk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "state": "ONGOING",
    "content": {
      "template": "generic",
      "progress": 0.0,
      "state": "Starting...",
      "icon": "arrow.triangle.branch",
      "accent_color": "cyan"
    }
  }'
Update progress
curl -X PATCH https://api.pushward.app/activity/my-build \
  -H "Authorization: Bearer hlk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "state": "ONGOING",
    "content": {
      "template": "generic",
      "progress": 0.75,
      "state": "Running tests...",
      "icon": "arrow.triangle.branch",
      "accent_color": "cyan"
    }
  }'
End activity
curl -X PATCH https://api.pushward.app/activity/my-build \
  -H "Authorization: Bearer hlk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "state": "ENDED",
    "content": {
      "template": "generic",
      "progress": 1.0,
      "state": "Complete",
      "icon": "checkmark.circle.fill",
      "accent_color": "green"
    }
  }'

Python

pushward.py
import requests

BASE_URL = "https://api.pushward.app"
TOKEN = "hlk_YOUR_KEY"
HEADERS = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json",
}

# Create activity
requests.post(f"{BASE_URL}/activities", headers=HEADERS, json={
    "slug": "my-build",
    "name": "My Build",
})

# Start activity
requests.patch(f"{BASE_URL}/activity/my-build", headers=HEADERS, json={
    "state": "ONGOING",
    "content": {
        "template": "generic",
        "progress": 0.0,
        "state": "Starting...",
        "icon": "arrow.triangle.branch",
        "accent_color": "cyan",
    },
})

# Update progress
requests.patch(f"{BASE_URL}/activity/my-build", headers=HEADERS, json={
    "state": "ONGOING",
    "content": {
        "template": "generic",
        "progress": 0.75,
        "state": "Running tests...",
        "icon": "arrow.triangle.branch",
        "accent_color": "cyan",
    },
})

# End activity
requests.patch(f"{BASE_URL}/activity/my-build", headers=HEADERS, json={
    "state": "ENDED",
    "content": {
        "template": "generic",
        "progress": 1.0,
        "state": "Complete",
        "icon": "checkmark.circle.fill",
        "accent_color": "green",
    },
})

Go

main.go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
)

const (
	baseURL = "https://api.pushward.app"
	token   = "hlk_YOUR_KEY"
)

func main() {
	// Create activity
	post("/activities", map[string]any{
		"slug": "my-build",
		"name": "My Build",
	})

	// Start activity
	patch("/activity/my-build", map[string]any{
		"state": "ONGOING",
		"content": map[string]any{
			"template":     "generic",
			"progress":     0.0,
			"state":        "Starting...",
			"icon":         "arrow.triangle.branch",
			"accent_color": "cyan",
		},
	})

	// Update progress
	patch("/activity/my-build", map[string]any{
		"state": "ONGOING",
		"content": map[string]any{
			"template":     "generic",
			"progress":     0.75,
			"state":        "Running tests...",
			"icon":         "arrow.triangle.branch",
			"accent_color": "cyan",
		},
	})

	// End activity
	patch("/activity/my-build", map[string]any{
		"state": "ENDED",
		"content": map[string]any{
			"template":     "generic",
			"progress":     1.0,
			"state":        "Complete",
			"icon":         "checkmark.circle.fill",
			"accent_color": "green",
		},
	})
}

func post(path string, body map[string]any) {
	doRequest("POST", path, body)
}

func patch(path string, body map[string]any) {
	doRequest("PATCH", path, body)
}

func doRequest(method, path string, body map[string]any) {
	data, _ := json.Marshal(body)
	req, _ := http.NewRequest(method, baseURL+path, bytes.NewReader(data))
	req.Header.Set("Authorization", "Bearer "+token)
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	defer resp.Body.Close()
	fmt.Printf("%s %s -> %d\n", method, path, resp.StatusCode)
}

JavaScript

pushward.js
const BASE_URL = "https://api.pushward.app";
const TOKEN = "hlk_YOUR_KEY";

const headers = {
  Authorization: `Bearer ${TOKEN}`,
  "Content-Type": "application/json",
};

// Create activity
await fetch(`${BASE_URL}/activities`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    slug: "my-build",
    name: "My Build",
  }),
});

// Start activity
await fetch(`${BASE_URL}/activity/my-build`, {
  method: "PATCH",
  headers,
  body: JSON.stringify({
    state: "ONGOING",
    content: {
      template: "generic",
      progress: 0.0,
      state: "Starting...",
      icon: "arrow.triangle.branch",
      accent_color: "cyan",
    },
  }),
});

// Update progress
await fetch(`${BASE_URL}/activity/my-build`, {
  method: "PATCH",
  headers,
  body: JSON.stringify({
    state: "ONGOING",
    content: {
      template: "generic",
      progress: 0.75,
      state: "Running tests...",
      icon: "arrow.triangle.branch",
      accent_color: "cyan",
    },
  }),
});

// End activity
await fetch(`${BASE_URL}/activity/my-build`, {
  method: "PATCH",
  headers,
  body: JSON.stringify({
    state: "ENDED",
    content: {
      template: "generic",
      progress: 1.0,
      state: "Complete",
      icon: "checkmark.circle.fill",
      accent_color: "green",
    },
  }),
});