master
Models
Introduction

Overview

The IONOS Cloud SDK for GO provides you with access to the IONOS Cloud API. The client library supports both simple and complex requests. It is designed for developers who are building applications in GO . The SDK for GO wraps the IONOS Cloud API. All API operations are performed over SSL and authenticated using your IONOS Cloud portal credentials. The API can be accessed within an instance running in IONOS Cloud or directly over the Internet from any application that can send an HTTPS request and receive an HTTPS response.

Getting Started

Before you begin you will need to have signed-up for a IONOS Cloud account. The credentials you setup during sign-up will be used to authenticate against the API.

Installation

Install the Go language from from the official Go installation guide.
The GOPATH environment variable specifies the location of your Go workspace. It is likely the only environment variable you will need to set when developing Go code. This is an example of pointing to a workspace configured under your home directory:
1
mkdir -p ~/go/bin
2
export GOPATH=~/go
3
export GOBIN=$GOPATH/bin
4
export PATH=$PATH:$GOBIN
Copied!
The following go command will download sdk-go to your configured GOPATH:
1
go get "github.com/ionos-cloud/sdk-go"
Copied!
The source code of the package will be located here:
1
$GOPATH/src/github.com/ionos-cloud/sdk-go
Copied!
Create main package file example.go:
1
package main
2
3
import (
4
"fmt"
5
)
6
7
func main() {
8
}
Copied!
Include the IONOS Cloud SDK for Go under the list of imports.
1
import(
2
"fmt"
3
4
"github.com/ionos-cloud/sdk-go"
5
)
Copied!

Authentication

The username and passwod or the authentication token can be manually specified when initializing the sdk client:
1
client := ionoscloud.NewAPIClient(ionoscloud.NewConfiguration(username, password, token, apiUrl))
Copied!
Environment variables can also be used. The sdk uses the following variables:
  • IONOS_USERNAME - to specify the username used to login
  • IONOS_PASSWORD - to specify the password
  • IONOS_TOKEN - if an authentication token is being used
  • IONOS_API_URL - to overwrite the api endpoint: api.ionos.com - if it is not set, the default value will be used
In this case, the client configuration needs to be initialized using NewConfigurationFromEnv()
1
client := ionoscloud.NewAPIClient(ionoscloud.NewConfigurationFromEnv())
Copied!
Caution: You will want to ensure you follow security best practices when using credentials within your code or stored in a file.

Environment Variables

Environment Variable
Description
IONOS_USERNAME
Specify the username used to login, to authenticate against the IONOS Cloud API
IONOS_PASSWORD
Specify the password used to login, to authenticate against the IONOS Cloud API
IONOS_TOKEN
Specify the token used to login, if a token is being used instead of username and password
IONOS_API_URL
Specify the API URL. It will overwrite the API endpoint default value api.ionos.com. Note: the host URL does not contain the /cloudapi/v5 path, so it should not be included in the IONOS_API_URL environment variable

Depth

Many of the List or Get operations will accept an optional depth argument. Setting this to a value between 0 and 5 affects the amount of data that is returned. The details returned vary depending on the resource being queried, however, it generally follows this pattern.
Depth
Description
0
Only direct properties are included. Children are not included.
1
Direct properties and children's references are returned.
2
Direct properties and children's properties are returned.
3
Direct properties, children's properties, and descendant's references are returned.
4
Direct properties, children's properties, and descendant's properties are returned.
5
Returns all available properties.

How to set Depth parameter:

⚠️ Please use this parameter with caution. We recommend using the default value and raising its value only if it is needed.
  • On the configuration level:
1
configuration := ionoscloud.NewConfiguration("USERNAME", "PASSWORD", "TOKEN", "URL")
2
configuration.SetDepth(5)
Copied!
Using this method, the depth parameter will be set on all the API calls.
  • When calling a method:
1
request := apiClient.DataCentersApi.DatacentersGet(context.Background()).Depth(1)
Copied!
Using this method, the depth parameter will be set on the current API call.
  • Using the default value:
If the depth parameter is not set, it will have the default value from the API that can be found here.
Note: The priority for setting the depth parameter is: set on function call > set on configuration level > set using the default value from the API

Pretty

The operations will also accept an optional pretty argument. Setting this to a value of true or false controls whether response is pretty-printed (with indentation and new lines). By default, the SDK sets the pretty argument to true.

Changing the base URL

Changing the base URL for the HTTP operation is possible by using the following function:
1
requestProperties.SetURL("https://api.ionos.com/cloudapi/v6")
Copied!

Feature Reference

The IONOS Cloud SDK for GO aims to offer access to all resources in the IONOS Cloud API and also offers some additional features that make the integration easier:
  • authentication for API calls
  • handling of asynchronous requests

FAQ

  1. 1.
    How can I open a bug/feature request?
Bugs & feature requests can be open on the repository issues: https://github.com/ionos-cloud/sdk-go/issues/new/choose
  1. 1.
    Can I contribute to the GO SDK?
Pure SDKs are automatically generated using OpenAPI Generator and don’t support manual changes. If you need changes please open an issue and we’ll try to take care of it.

Debugging

If you want to see the API call request and response messages, you need to set the Debug field in the Configuration struct:
1
package main
2
import "github.com/ionos-cloud/sdk-go/v5"
3
func main() {
4
// create your configuration. replace username, password, token and url with correct values, or use NewConfigurationFromEnv()
5
// if you have set your env variables as explained above
6
cfg := ionoscloud.NewConfiguration("username", "password", "token", "hostUrl")
7
// enable request and response logging
8
cfg.Debug = true
9
// create you api client with the configuration
10
apiClient := ionoscloud.NewAPIClient(cfg)
11
}
Copied!
⚠️ Note: We recommend you only set this field for debugging purposes. Disable it in your production environments because it can log sensitive data. It logs the full request and response without encryption, even for an HTTPS call. Verbose request and response logging can also significantly impact your application’s performance.
Last modified 3mo ago