Skip to content

orijtech/asana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

asana

Asana API client implemented in Go

Requirements:

  • Personal Authentication Token set in your environment as ASANA_PERSONAL_ACCESS_TOKEN or you could pass in a key when initializing a client.

  • Currently their API only has v1 so that's the client we'll use.

Preamble:

import (
	"fmt"
	"log"
	"os"

	"github.com/odeke-em/asana/v1"
)

Example creating a task

func main() {
	client, err := asana.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	setupServers, err := client.CreateTask(&asana.TaskRequest{
		Assignee:  "[email protected]",
		Notes:     "Please ensure to setup the servers, then ping our group",
		Name:      "server setup",
		Workspace: "331783765164429",
		Followers: []asana.UserID{
			"[email protected]",
		},
	})

	if err != nil {
		log.Fatalf("the error: %#v", err)
	}

	log.Printf("Here is the task: %#v", setupServers)
}

List all your workspaces

func main() {
	client, err := asana.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	workspacesChan, err := client.ListMyWorkspaces()
	if err != nil {
		log.Fatal(err)
	}

	pageCount := 0
	for page := range workspacesChan {
		for i, workspace := range page.Workspaces {
			log.Printf("Page: #%d i: %d workspace: %#v", pageCount, i, workspace)
		}
		pageCount  = 1
	}
}

Find an attachment by id

func main() {
	client, err := asana.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	foundAttachment, err := client.FindAttachmentByID("5678")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Found attachment: %#v\n", foundAttachment)
}

Upload an attachment to a task

func main() {
	imageR, err := os.Open("./testdata/messengerQR.png")
	if err != nil {
		log.Fatal(err)
	}
	defer imageR.Close()

	client, err := asana.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	respAttachment, err := client.UploadAttachment(&asana.AttachmentUpload{
		TaskID: "331727965981099",
		Name:   "messenger QR code",
		Body:   imageR,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Response attachment: %#v\n", respAttachment)
}

List all attachments for a task

func main() {
	client, err := asana.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	attachmentsPage, err := client.ListAllAttachmentsForTask("331727965981099")
	if err != nil {
		log.Fatal(err)
	}

	for i, task := range attachmentsPage.Attachments {
		fmt.Printf("Task #%d: %#v\n\n", i, task)
	}
}

Releases

No releases published

Packages

No packages published

Languages