This Go package provides a wrapper to interact with the Aircall API
go get -u github.com/leoht/aircall
package main
import (
"fmt"
"github.com/leoht/aircall"
)
func main() {
// Create the client with your API id and secret
client := aircall.NewClient("<your app ID>", "<your app secret")
// Get current company info
// Returns a CompanyResponse struct
res, err := client.Company()
if err != nil {
panic(err)
}
company = res.Company
fmt.Println("Company name", company.Name)
// Get users list
res, err := client.Users(aircall.Paginate{
PerPage: 10
})
if err != nil {
panic(err)
}
for _, u := range res.Users {
fmt.Println("User", u.ID, u.Name)
// Get specific user
userRes, err := client.User(user.ID)
}
// Get numbers
res, err := client.Numbers(aircall.Paginate{
PerPage: 10,
Page: 2
})
if err != nil {
panic(err)
}
for _, num := range res.Numbers {
fmt.Println("Number", num.ID, num.Name, num.Digits)
}
}
Each API call function returns a specific struct type to hold the response data. See messages.go to view all possible response types, and types.go to view the possible entity types.
For all calls returning a lis of entities (e.g Users()
or Contacts()
), an attribute Meta
will be present
in the response struct. This attribute is a struct containing Count
, Total
, CurrentPage
, PerPage
, NextPageLink
and PreviousPageLink
.
res, err := client.Company()
company := res.Company
fmt.Println("Company: ", company.Name)
// Default pagination parameters
res, err := client.Users(aircall.Paginate{})
for _, user := range res.Users {
fmt.Println("User: ", user.ID)
}
// With pagination
res, err := client.Users(aircall.Paginate{
Page: 1,
PerPage: 5,
Order: "asc"
})
res, err := client.User(123456)
user := res.User
fmt.Println("User: ", user.ID)
res, err := client.Numbers(aircall.Paginate{})
for _, number := range res.Numbers {
fmt.Println("Number: ", number.ID, number.Digits)
}
res, err := client.Number(153434)
number := res.Number
fmt.Println("Number: ", number.ID, number.Digits)
res, err := client.Calls(aircall.Paginate{})
for _, call := range res.Calls {
fmt.Println("Call: ", call.ID)
}
res, err := client.Call(12345)
call := res.Call
fmt.Println("Call: ", call.ID, call)
link := "http://www.mycompany.com"
res, err := client.LinkCall(12345, link)
userID := 16354
res, err := client.TransferCall(12345, userID)
callID := 16354
_, err := client.DeleteRecording(callID)
callID := 16354
_, err := client.DeleteVoicemail(callID)
// Default pagination parameters
res, err := client.Contacts(aircall.Paginate{})
for _, contact := range res.Contacts {
fmt.Println("Contact: ", contact.ID)
}
res, err := client.Contact(12345)
contact := res.Contact
fmt.Println("Contact: ", contact.ID, contact.FirstName)
req = aircall.ContactRequest{
FirstName: "John",
LastName: "Doe",
CompanyName: "Acme",
PhoneNumbers: []aircall.ContactInfo{
aircall.ContactInfo{
Label: "Pro phone",
Value: "+33600112233",
},
},
}
res, err := client.CreateContact(req)
contact := res.Contact
fmt.Println("Contact created: ", contact.ID, contact.FirstName)
contactID := 15364
req = aircall.ContactRequest{
CompanyName: "Acme 2.0",
}
res, err := client.UpdateContact(contactID, req)
contact := res.Contact
fmt.Println("Contact created: ", contact.ID, contact.FirstName)
res, err := client.SearchContacts(
aircall.Paginate{},
aircall.Search{
PhoneNumber: "+441001123344",
},
)
for _, contact := range res.Contacts {
fmt.Println("Contact: ", contact.ID)
}
contactID := 16354
_, err := client.DeleteContact(contactID)