> For the complete documentation index, see [llms.txt](https://docs.licensespring.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.licensespring.com/sdks/go-sdk/v1-legacy/management-client.md).

# Management Client

{% hint style="info" %}
LicenseSpring’s new [**Go SDK V2**](broken://pages/ae2a7abe98ac54bb39ee8fc9e008316b6c214907) is now available! This version is a complete rewrite with breaking changes and will receive all future updates and support.

The legacy Go SDK (v1) is deprecated and maintained for backward compatibility only. New users should use v2.
{% endhint %}

> **Note:** Read [**Common**](broken://pages/ba35f6f80b4e589e98545732a1aa580f61301d98) before this.

#### Importing the Management Client

{% code title="imports.go" %}

```go
import(
  "gitlab.com/l3178/sdk-go/management_client"
  management_request "gitlab.com/l3178/sdk-go/management_client/models/request"
)
```

{% endcode %}

#### Creating the Client

{% code title="client.go" %}

```go
config := management_client.NewManagementClientConfiguration("managementKey")
c := management_client.NewManagementClient(config)
```

{% endcode %}

#### Customer API

{% code title="customer\_api\_test.go" %}

```go
ctx := context.Background()

t.Run("Create", func(t *testing.T) {
	resp := c.CustomerApi().CreateCustomer(ctx, management_request.CreateCustomerRequest{
		Email:     "ttt@ttt.ttt",
		FirstName: "Test",
	})
	require.NoError(t, resp.Error)
	id = resp.Value.Id
})

t.Run("List", func(t *testing.T) {
	resp := c.CustomerApi().ListCustomers(ctx, management_request.SearchCustomersRequest{
		Email: "ttt@ttt.ttt",
	})
	assert.NoError(t, resp.Error)
	assert.Equal(t, 1, resp.Count)
})

t.Run("Edit", func(t *testing.T) {
	resp := c.CustomerApi().EditCustomer(ctx, id, management_request.CreateCustomerRequest{
		LastName: "abcd",
	})
	assert.NoError(t, resp.Error)
})

t.Run("Get", func(t *testing.T) {
	resp := c.CustomerApi().ShowCustomer(ctx, id)
	assert.NoError(t, resp.Error)
	assert.Equal(t, "abcd", resp.Value.LastName)
})

t.Run("Delete", func(t *testing.T) {
	err := c.CustomerApi().DeleteCustomer(ctx, id)
	assert.NoError(t, err)
})

t.Run("Create", func(t *testing.T) {
	resp := c.CustomerApi().CreateCustomerLabel(ctx, management_request.CreateCustomerLabelRequest{
		Label: "abcd",
		Color: "efgh",
	})
	require.NoError(t, resp.Error)
	id = resp.Value.Id
})

t.Run("List", func(t *testing.T) {
	resp := c.CustomerApi().ListCustomerLabels(ctx, management_request.SearchRequest{})
	assert.NoError(t, resp.Error)
	assert.Equal(t, 1, resp.Count)
})

t.Run("Edit", func(t *testing.T) {
	resp := c.CustomerApi().EditCustomerLabel(ctx, id, management_request.CreateCustomerLabelRequest{
		Color: "1234",
	})
	assert.NoError(t, resp.Error)
})

t.Run("Get", func(t *testing.T) {
	resp := c.CustomerApi().ShowCustomerLabel(ctx, id)
	assert.NoError(t, resp.Error)
	assert.Equal(t, "1234", resp.Value.Color)
})

t.Run("Delete", func(t *testing.T) {
	err := c.CustomerApi().DeleteCustomerLabel(ctx, id)
	assert.NoError(t, err)
})

t.Run("Create", func(t *testing.T) {
	resp := c.CustomerApi().CreateCustomerAccount(ctx, management_request.CreateCustomerAccountRequest{
		Code: "abcd",
		Name: "efgh",
	})
	require.NoError(t, resp.Error)
	id = resp.Value.Id
})

t.Run("List", func(t *testing.T) {
	resp := c.CustomerApi().ListCustomerAccounts(ctx, management_request.SearchRequest{})
	assert.NoError(t, resp.Error)
	assert.Equal(t, 1, resp.Count)
})

t.Run("Edit", func(t *testing.T) {
	resp := c.CustomerApi().EditCustomerAccount(ctx, id, management_request.CreateCustomerAccountRequest{
		Description: "test",
	})
	assert.NoError(t, resp.Error)
})

t.Run("Get", func(t *testing.T) {
	resp := c.CustomerApi().ShowCustomerAccount(ctx, id)
	assert.NoError(t, resp.Error)
	assert.Equal(t, "test", resp.Value.Description)
})

t.Run("Delete", func(t *testing.T) {
	err := c.CustomerApi().DeleteCustomerAccount(ctx, id)
	assert.NoError(t, err)
})
```

{% endcode %}

#### Device API

{% code title="device\_api\_test.go" %}

```go
ctx := context.Background()

t.Run("SearchDevices", func(t *testing.T) {
	resp := c.DeviceApi().ListDevices(ctx, management_request.SearchDevicesRequest{
		License: testLicenseID,
	})
	assert.NoError(t, resp.Error)
})

t.Run("ShowDevice", func(t *testing.T) {
	c.DeviceApi().ShowDevice(ctx, deviceID)
})

t.Run("ResetDevice", func(t *testing.T) {
	c.DeviceApi().ResetDevice(ctx, deviceID)
})

t.Run("BlacklistDevice", func(t *testing.T) {
	c.DeviceApi().BlacklistDevice(ctx, deviceID)
})

t.Run("CreateDeviceVariable", func(t *testing.T) {
	resp := c.DeviceApi().CreateDeviceVariable(ctx, management_request.CreateDeviceVariableRequest{
		Variable: "test",
		Value:    "value",
		Device:   deviceID,
	})
	assert.NoError(t, resp.Error)
})

t.Run("UpdateDeviceVariable", func(t *testing.T) {
	resp := c.DeviceApi().UpdateDeviceVariable(ctx, deviceID, management_request.UpdateDeviceVariableRequest{
		Variable: "test",
		Value:    "value",
	})
	assert.NoError(t, resp.Error)
})

t.Run("DeleteDeviceVariable", func(t *testing.T) {
	err := c.DeviceApi().DeleteDeviceVariable(ctx, deviceID)
	assert.NoError(t, err)
})

t.Run("SearchDeviceVariable", func(t *testing.T) {
	resp := c.DeviceApi().ListDeviceVariables(ctx, management_request.SearchDeviceVariablesRequest{
		Device: deviceID,
	})
	assert.NoError(t, resp.Error)
})

t.Run("ShowDeviceVariable", func(t *testing.T) {
	resp := c.DeviceApi().ShowDeviceVariable(ctx, deviceID)
	assert.NoError(t, resp.Error)
})
```

{% endcode %}

#### License API

{% code title="license\_api\_test.go" %}

```go
ctx := context.Background()

t.Run("Disable", func(t *testing.T) {
	resp := c.LicenseApi().DisableLicense(ctx, testLicenseID)
	assert.NoError(t, resp.Error)
})

t.Run("Get", func(t *testing.T) {
	resp := c.LicenseApi().GetLicense(ctx, testLicenseID)
	assert.NoError(t, resp.Error)
	assert.False(t, resp.Value.Enabled)
})

t.Run("Enable", func(t *testing.T) {
	resp := c.LicenseApi().EnableLicense(ctx, testLicenseID)
	assert.NoError(t, resp.Error)
})

t.Run("Update", func(t *testing.T) {
	resp := c.LicenseApi().UpdateLicense(ctx, testLicenseID, management_request.UpdateLicenseRequest{
		MaxActivations: 5,
	})
	assert.NoError(t, resp.Error)
})

t.Run("List", func(t *testing.T) {
	resp := c.LicenseApi().SearchLicenses(ctx, management_request.SearchLicensesRequest{})
	assert.NoError(t, resp.Error)
	assert.Equal(t, 3, resp.Count)
})

t.Run("Assign", func(t *testing.T) {
	resp := c.LicenseApi().AssignUser(ctx, testUserLicenseID, management_request.AssignUserToLicenseRequest{
		Email:    "test@abcd.efgh",
		Password: "abcdefgh",
	})
	assert.NoError(t, resp.Error)
})

t.Run("List", func(t *testing.T) {
	resp := c.LicenseApi().ListLicenseUsers(ctx, management_request.SearchUsersRequest{
		EmailContains: "test@abcd.efgh",
	})
	assert.NoError(t, resp.Error)
	require.Equal(t, 1, resp.Count)
	userID = resp.Results[0].Id
})

t.Run("Password", func(t *testing.T) {
	resp := c.LicenseApi().SetUserPassword(ctx, userID, management_request.SetPasswordRequest{
		Password: "test",
	})
	assert.NoError(t, resp.Error)
})

t.Run("Unassign", func(t *testing.T) {
	resp := c.LicenseApi().UnassignUser(ctx, testUserLicenseID, management_request.UnassignRequest{
		LicenseUserId: userID,
	})
	assert.NoError(t, resp.Error)
})

t.Run("List", func(t *testing.T) {
	resp := c.LicenseApi().SearchLicenseCustomFields(ctx, management_request.SearchLicenseCustomFieldsRequest{
		License: testLicenseID,
	})
	require.NoError(t, resp.Error)
	require.Equal(t, 1, resp.Count)
	id = resp.Results[0].Id
})

t.Run("Get", func(t *testing.T) {
	resp := c.LicenseApi().GetLicenseCustomField(ctx, id)
	assert.NoError(t, resp.Error)
})

t.Run("Update", func(t *testing.T) {
	resp := c.LicenseApi().UpdateLicenseCustomField(ctx, id, management_request.UpdateCustomLicenseFieldRequest{
		Value: "test",
	})
	assert.NoError(t, resp.Error)
})
```

{% endcode %}

#### Order API

{% code title="order\_api\_test.go" %}

```go
ctx := context.Background()

t.Run("SearchOrders", func(t *testing.T) {
	resp := c.OrderApi().SearchOrders(ctx, management_request.SearchOrdersRequest{})
	assert.NoError(t, resp.Error)
})

t.Run("GetOrder", func(t *testing.T) {
	resp := c.OrderApi().GetOrder(ctx, orderID)
	assert.NoError(t, resp.Error)
})

t.Run("CreateOrder", func(t *testing.T) {
	resp := c.OrderApi().CreateOrder(ctx, management_models.WebhookOrder{
		Items: []management_models.OrderItem{
			{
				ProductCode: "code",
				Licenses: []management_models.OrderLicense{
					{
						Key: "key",
					},
				},
			},
		},
	})
	assert.NoError(t, resp.Error)
})

t.Run("ExportToCSV", func(t *testing.T) {
	timeStart := time.Now().Add(-5 * time.Hour)
	timeEnd := time.Now()
	resp := c.OrderApi().ExportToCsv(ctx, timeStart, timeEnd)
	assert.NoError(t, resp.Error)
})

t.Run("ExportToCSVRange", func(t *testing.T) {
	var r management_models.Range
	r = r.Last30()
	resp := c.OrderApi().ExportToCsvRange(ctx, r)
	assert.NoError(t, resp.Error)
})

t.Run("GenerateLicenseKeys", func(t *testing.T) {
	resp := c.OrderApi().GenerateLicenseKeys(ctx, management_request.GenerateLicenseRequest{
		Product:  "product",
		Quantity: 1,
	})
	assert.NoError(t, resp.Error)
})

t.Run("AddManagerToOrder", func(t *testing.T) {
	resp := c.OrderApi().AddManagerToOrder(ctx, orderID, management_request.AddManagerToOrderRequest{
		Email:    "email",
		Password: "password",
	})
	assert.NoError(t, resp.Error)
})
```

{% endcode %}

#### Product API

{% code title="product\_api\_test.go" %}

```go
ctx := context.Background()

t.Run("List", func(t *testing.T) {
	resp := c.ProductApi().ListProducts(ctx, management_request.SearchProductsRequest{})
	assert.NoError(t, resp.Error)
	assert.Equal(t, 2, resp.Count)
})

t.Run("Show", func(t *testing.T) {
	resp := c.ProductApi().ShowProduct(ctx, testProductID)
	assert.NoError(t, resp.Error)
})

t.Run("Create", func(t *testing.T) {
	resp := c.ProductApi().CreateInstallationFile(ctx, management_request.CreateInstallationFileRequest{
		FullLink: "link",
		Product:  testProductID,
		Version:  "v1",
	})
	assert.NoError(t, resp.Error)
	id = resp.Value.Id
})

t.Run("List", func(t *testing.T) {
	resp2 := c.ProductApi().ListInstallationFiles(ctx, management_request.SearchInstallationFilesRequest{
		Product: testProductID,
	})
	assert.NoError(t, resp2.Error)
})

t.Run("Show", func(t *testing.T) {
	resp3 := c.ProductApi().ShowInstallationFile(ctx, id)
	assert.NoError(t, resp3.Error)
})

t.Run("Create", func(t *testing.T) {
	resp := c.ProductApi().CreateProductCustomField(ctx, management_request.CreateProductCustomFieldRequest{
		Name:         "field",
		DefaultValue: "test",
		Product:      testProductID,
	})
	assert.NoError(t, resp.Error)
	id = resp.Value.Id
})

t.Run("Show1", func(t *testing.T) {
	respShow := c.ProductApi().ShowProductCustomField(ctx, id)
	assert.NoError(t, respShow.Error)
	assert.Equal(t, "test", respShow.Value.DefaultValue)
})

t.Run("Update", func(t *testing.T) {
	respUpdate := c.ProductApi().UpdateProductCustomField(ctx, id, management_request.UpdateProductCustomFieldRequest{
		Name:         "field",
		DefaultValue: "abcd",
	})
	assert.NoError(t, respUpdate.Error)
})

t.Run("Show2", func(t *testing.T) {
	respShow := c.ProductApi().ShowProductCustomField(ctx, id)
	assert.NoError(t, respShow.Error)
	assert.Equal(t, "abcd", respShow.Value.DefaultValue)
})

t.Run("Delete", func(t *testing.T) {
	err := c.ProductApi().DeleteProductCustomField(ctx, id)
	assert.NoError(t, err)
})

t.Run("List", func(t *testing.T) {
	respList := c.ProductApi().ListProductCustomFields(ctx, management_request.SearchProductCustomFieldsRequest{
		Product: testProductID,
	})
	assert.NoError(t, respList.Error)
	assert.Equal(t, 1, respList.Count)
})
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/sdks/go-sdk/v1-legacy/management-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
