Installation

You can install the package using go get:
https://github.com/cocoonmail/cocoonmail-go/
Minimum Go version required: 1.20+ You will need a Cocoonmail API key to use the SDK. In your Cocoonmail account, go to the API Settings page and click Generate key. Copy this key and save it in your application code (for example as an environment variable COCOONMAIL_API_KEY ).

Usage

package main

import (
  "fmt"
  "log"
  "os"

  cocoonmail "github.com/cocoonmail/cocoonmail-go"
)

func main() {
  client := cocoonmail.NewClient(os.Getenv("COCOONMAIL_API_KEY"))

  resp, err := client.CreateContact("email@provider.com", nil, nil)
  if err != nil {
    log.Fatal(err)
  }

  fmt.Printf("Created contact: %+v\n", resp)
}

Default contact properties

Each contact in Cocoonmail has a set of default properties. These will always be returned in API results.
  • id
  • email
  • firstName
  • lastName
  • source
  • subscribed
  • userGroup
  • userId

Custom contact properties

You can use custom contact properties in API calls. Make sure to add custom properties in your Cocoonmail account before using them with the SDK.

TestApiKey

API Reference

Example

resp, err := client.TestApiKey()
if err != nil {
  log.Fatal(err)
}
fmt.Println(resp.TeamName)

Response

{
  "success": true,
  "teamName": "My team"
}

CreateContact

Example

props := map[string]interface{}{
  "firstName": "Bob",
  "favoriteColor": "Red",
}
mailingLists := map[string]bool{
  "cm06f5v0e45nf0ml5754o9cix": true,
}
resp, err := client.CreateContact("hello@gmail.com", props, mailingLists)
if err != nil {
  log.Fatal(err)
}
fmt.Println(resp.ID)

UpdateContact()

Update an existing contact.
Note: To update a contact’s email address, the contact requires a userId.
Then you can make a request with their userId and an updated email address.
API Reference

Parameters

NameTypeRequiredNotes
emailstringYesThe email address of the contact to update. If no contact exists with this email, a new contact will be created using the email and properties.
propertiesmap[string]interfaceNoDefault or custom contact properties (must exist in your Cocoonmail account). Values can be string, number, bool, null, or date.
mailingListsmap[string]boolNoMailing list IDs and subscription statuses.

Example

props := map[string]interface{}{
  "firstName": "Alice",
  "favoriteColor": "Blue",
}

resp, err := client.UpdateContact("hello@gmail.com", props, nil)
if err != nil {
  log.Fatal(err)
}
fmt.Println(resp.ID)

// Updating contact’s email with userId
props2 := map[string]interface{}{
  "userId": "1234",
}
resp, err = client.UpdateContact("newemail@gmail.com", props2, nil)

Response

{
  "success": true,
  "id": "id_of_contact"
}
{
  "success": false,
  "message": "An error message here."
}

FindContact()

Find a contact by email or userId.

Parameters

You must provide one parameter.
NameTypeRequiredNotes
emailstringNo
userIdstringNo

Example

resp, err := client.FindContact(map[string]string{
  "email": "hello@gmail.com",
})
if err != nil {
  log.Fatal(err)
}
fmt.Printf("%+v\n", resp)

resp, err = client.FindContact(map[string]string{
  "userId": "12345",
})

Response

[
  {
    "id": "cll6b3i8901a9jx0oyktl2m4u",
    "email": "hello@gmail.com",
    "firstName": "Alice",
    "lastName": null,
    "source": "API",
    "subscribed": true,
    "userGroup": "",
    "userId": "12345",
    "mailingLists": {
      "cm06f5v0e45nf0ml5754o9cix": true
    },
    "favoriteColor": "Blue"
  }
]

DeleteContact()

Delete a contact, either by email or userId.

Parameters

You must use one parameter.
NameTypeRequiredNotes
emailstringNo
userIdstringNo

Example

// Delete by email
resp, err := client.DeleteContact(map[string]string{
  "email": "hello@gmail.com",
})
if err != nil {
  log.Fatal(err)
}
fmt.Println(resp.Message)

// Delete by userId
resp, err = client.DeleteContact(map[string]string{
  "userId": "12345",
})

Response

{
  "success": true,
  "message": "Contact deleted successfully"
}
{
  "success": false,
  "message": "An error message here."
}
---

This keeps the **same structure** as your JavaScript docs but adapted for Go (with maps instead of objects, proper `err` handling, etc.).  

👉 Do you also want me to extend it for **sendEvent()** and **sendTransactionalEmail()** in Go, the way you have them in JS? That way your `go.mdx` will be a complete mirror of `javascript.mdx`.