Skip to content

API Client implementation in Go

For the source code, refer to GitHub.

Using API Key Authentication

import "github.com/definitepotato/espocrm"

client := espocrm.NewApiClient(
    "https://espocrm.example.com",
    espocrm.WithApiKeyAuth("Your API Key here"),
)

Using Basic Authentication

(this is highly discouraged)

import "github.com/definitepotato/espocrm"

client := espocrm.NewApiClient(
    "https://espocrm.example.com",
    espocrm.WithBasicAuth("username", "password"),
)

Making a list GET request

import "github.com/definitepotato/espocrm"

parameters := espocrm.NewParameters(
    espocrm.SetWhere([]espocrm.Where{
        {
            Type: espocrm.Equals,
            Attribute: "myAttribute",
            Value: "myValue",
        },
    }),
)

client := espocrm.NewApiClient(
    "https://espocrm.example.com",
    espocrm.WithApiKeyAuth("Your API Key here"),
)

contacts, err := client.List("Contact", parameters)

Making a read GET request

import "github.com/definitepotato/espocrm"

client := espocrm.NewApiClient(
    "https://espocrm.example.com",
    espocrm.WithApiKeyAuth("Your API Key here"),
)

contact, err := client.Read("Contact", "78abc123def456")

Making a create POST request

import "github.com/definitepotato/espocrm"

newContact := `"{ "name": "Test", "assignedUserId": "1" }"`

client := espocrm.NewApiClient(
    "https://espocrm.example.com",
    espocrm.WithApiKeyAuth("Your API Key here"),
)

attributes, err := client.Create("Contact", newContact)

Making an update PUT request

import "github.com/definitepotato/espocrm"

contactID := "993bdd81479dff4"
updatePayload := `"{ assignedUserId": "1" }"`

client := espocrm.NewApiClient(
    "https://espocrm.example.com",
    espocrm.WithApiKeyAuth("Your API Key here"),
)

attributes, err := client.Update("Contact", contactID, updatePayload)

Making a delete DELETE request

import "github.com/definitepotato/espocrm"

contactID := "78abc123def456"
client := espocrm.NewApiClient(
    "https://espocrm.example.com",
    espocrm.WithApiKeyAuth("Your API Key here"),
)

status, err := client.Delete("Contact", contactID)