Start using our API in 5 minutes
Learn how to use our API with our quick API guide
Step 1: Generate your API Key
You can generate your API key at the Customer Portal. For more information regarding API keys you can visit our Knowledge Base.
Step 2: Authenticate your API call
In order to access our API, you will need to issue your requests against https://api.leaseweb.com
. To authenticate your call, add your API key to the request header `X-Lsw-Auth`
.
Step 3: Make your first API call
Now that you know how to authenticate an API call, it is time to make your first test call. In this example, you will retrieve a list of Bare Metal Servers you currently have at Leaseweb. To begin, your first request may look like this:
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.leaseweb.com/bareMetals/v2/servers"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Printf("Error creating request: %v\n", err)
return
}
req.Header.Add("x-lsw-auth", "LEASEWEB_API_KEY")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error making GET request: %v\n", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Printf("Error: received non-200 status code %d\n", resp.StatusCode)
return
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response body: %v\n", err)
return
}
fmt.Println(string(body))
}
Step 4: Get to know the API
Now that you learned how to use our API, you may want to take a look to our complete API References.