This is the documentation for the Golang SDK for Basiq.io API
Basiq.io Golang SDK is a set of tools you can use to easily communicate with Basiq API. If you want to get familiar with the API docs, click here.
The SDK is organized to mirror the HTTP API's functionality and hierarchy. The top level object needed for SDKs functionality is the Session object which requires your API key to be instantiated. You can grab your API key on the dashboard.
1.0.2 - Documentation updated, added RefreshToken method on the Session object
1.0.1 - Documentation updated
1.0.0 - Supported 2.0 API version
0.9.0beta - Initial release
Now that you have your API key, you can use the following command to install the SDK:
go get -u github.com/basiqio/basiq-sdk-golang/
In order to instantiate Session object, following package should be imported:
import (
"github.com/basiqio/basiq-sdk-golang/basiq"
)
Services for API version 1.0 are located in v1 package:
import (
"github.com/basiqio/basiq-sdk-golang/v1"
)
Services for API version 2.0 are located in v2 package:
import (
"github.com/basiqio/basiq-sdk-golang/v2"
)
You can fetch a list of supported financial institutions. The function returns a list of Institution structs.
package main
import (
"github.com/basiqio/basiq-sdk-golang/basiq"
"log"
)
func main() {
session, err := basiq.NewSessionV1("YOUR_API_KEY")
if err != nil {
log.Printf("%+v", err)
}
institutions, err := session.GetInstitutions()
if err != nil {
log.Printf("%+v", err)
}
}
Fetching institutions v2.0:
package main
import (
"github.com/basiqio/basiq-sdk-golang/basiq"
"log"
)
func main() {
session, err := basiq.NewSessionV2("YOUR_API_KEY")
if err != nil {
log.Printf("%+v", err)
}
institutions, err := session.GetInstitutions()
if err != nil {
log.Printf("%+v", err)
}
}
When a new connection request is made, the server will create a job that will link user's financial institution with your app.
package main
import (
"github.com/basiqio/basiq-sdk-golang/basiq"
"log"
)
func main() {
session, err := basiq.NewSessionV1("YOUR_API_KEY")
if err != nil {
log.Printf("%+v", err)
}
user := session.ForUser(userId)
job, err := user.CreateConnection(&services.ConnectionData{
Institution: &services.InstitutionData{
Id: "AU00000",
},
LoginId: "gavinBelson",
Password: "hooli2018",
})
if err != nil {
log.Printf("%+v", err)
}
// Poll our server to wait for the credentials step to be evaluated
connection, err := job.WaitForCredentials(1000, 60)
if err != nil {
log.Printf("%+v", err)
}
}
In this example, the function returns a transactions list struct which is filtered by the connection.id property. You can iterate through transactions list by calling Next().
package main
import (
"github.com/basiqio/basiq-sdk-golang/basiq"
"log"
)
func main() {
session, err := basiq.NewSessionV1("YOUR_API_KEY")
if err != nil {
log.Printf("%+v", err)
}
user := session.ForUser(userId)
fb := utilities.FilterBuilder{}
fb.Eq("connection.id", "conn-id-213-id")
transactions, err := user.GetTransactions(&fb)
if err != nil {
log.Printf("%+v", err)
}
for {
next, err := transactions.Next()
if err != nil {
log.Printf("%+v", err)
break
}
if next == false {
break
}
log.Println("Next transactions len:", len(transactions.Data))
}
}
The API of the SDK is manipulated using Services and Entities. Different services return different entities, but the mapping is not one to one.
If an action encounters an error, you will receive an APIError instance. The struct contains all available data which you can use to act accordingly.
type ResponseError struct {
CorrelationId string `json:"correlationId"`
Data []ResponseErrorItem
}
type ResponseErrorItem struct {
Code string `json:"code"`
Title string `json:"title"`
Detail string `json:"detail"`
Source ErrorSource `json:"source"`
}
type APIError struct {
Data map[string]interface{}
Message string
Response ResponseError
StatusCode int
}
Check the docs for more information about relevant fields in the error object.
Some of the methods support adding filters to them. The filters are created using the FilterBuilder struct. After instantiating the struct, you can invoke methods in the form of Comparison(field, value).
Example:
fb := utilities.FilterBuilder{}
fb.Eq("connection.id", "conn-id-213-id").Gt("transaction.postDate", "2018-01-01")
transactions, err := user.GetTransactions(&fb)
This example filter for transactions will match all transactions for the connection with the id of "conn-id-213-id" and that are newer than "2018-01-01". All you have to do is pass its reference when you want to use it.
Services
session, err := basiq.NewSessionV1("YOUR_API_KEY")
session, err := basiq.NewSessionV2("YOUR_API_KEY")
err := session.RefreshToken()
institutions, err := session.GetInstitutions()
institution, err := session.GetInstitution("INSTITUTION_ID")
user, err := session.CreateUser(userData)
Note: The following action will not send an HTTP request, and can be used to perform additional actions for the instantiated user.
user := session.ForUser(userId)
The following are APIs available for the User service
userService := v1.NewUserService(session)
userService := v2.NewUserService(session)
Note: The following action will not send an HTTP request, and can be used to perform additional actions for the instantiated user.
user := userService.ForUser(userId)
user, err := userService.CreateUser(&Services.UserData{
Mobile: "+61410888555",
})
user, err := userService.GetUser(userId)
user, err := userService.UpdateUser(userId, &Services.UserData{})
err := userService.DeleteUser(userId)
err := userService.RefreshAllConnections(userId)
conns, err := userService.ListAllConnections(userId, *filter)
acc, err := userService.GetAccount(userId, accountId)
accs, err := userService.GetAccounts(userId, *filter)
transaction, err := userService.GetTransaction(userId, transactionId)
transactions, err := userService.GetTransactions(userId, *filter)
The following are APIs available for the Connection service
connService := v1.NewConnectionService(session, user)
connService := v2.NewConnectionService(session, user)
connection, err := connService.GetConnection(connectionId)
connection := connService.ForConnection(connectionId)
job, err := connService.NewConnection(*connectionData)
job, err := connService.UpdateConnection(connectionId, password)
err := connService.DeleteConnection(connectionId)
job, err := connService.GetJob(jobId)
The following are APIs available for the Transaction service
transactionService := v1.NewTransactionService(session)
transactionService := v2.NewTransactionService(session)
transactionList, err := transactionService.GetTransactions(userId, *filter)
The following are APIs available for the Institution service
instService := v1.NewInstitutionService(session, userId)
instService := v2.NewInstitutionService(session, userId)
institutions, err := instService.GetInstitutions()
institution, err := instService.GetInstitution(institutionId)
Entities
err := user.Update(&Services.UserData{
Mobile: "+61410888665",
})
err := user.Delete()
accounts, err := user.GetAccounts()
account, err := user.GetAccount(accountId)
transactions, err := user.GetTransactions()
transaction, err := user.GetTransaction(transactionId)
job, err := user.CreateConnection(&services.ConnectionData{
Institution: &services.InstitutionData{
Id: "AU00000",
},
LoginId: "gavinBelson",
Password: "hooli2018",
})
err := user.RefreshAllConnections()
job, err := connection.Refresh()
job, err := connection.Update(password)
err := connection.Delete()
connectionId := job.GetConnectionId()
connection, err := job.GetConnection()
(interval is in milliseconds, timeout is in seconds)
connection, err := job.WaitForCredentials(interval, timeout)
(interval is in milliseconds, timeout is in seconds)
connection, err := job.WaitForTransactions(interval, timeout)
next, err := transactions.Next()