Skip to content

Start

Hi there 👋 This is running SOMNOON api within your browser tab!

📖 Necessary condition

Before using the APIs listed in this article, make sure you get the API KEY correctly!

Create usable API Keys

This operation needs provider owner to be performed by the owner of the registered

  1. Log in to the SOMNOON Administrator page with the provider owner's account.

  2. Select Personal Settings from the menu under Personal Information in the upper right corner, and then click the API Key menu on the new page.

any

❗ The expiration date of API KEY use is related to the package of the provider, so please check when it cannot be used.

How to use

All APIs are used over HTTP and can generally be executed from the command line or by specific tools, as well as programmatically.

Use command line

Any line of the command line can be used.

shell
# curl - GET
curl --location 'https://api.somnoon.com/your url' \
--header 'x-api-key: your api key'
# curl - GET
curl --location 'https://api.somnoon.com/your url' \
--header 'x-api-key: your api key'

Or use an API debugging tool such as Postman, for details, please go to Postman

Javascript - fetch

javascript
var myHeaders = new Headers();
myHeaders.append("x-api-key", "your key");

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://ts-api.somnoon.com/your url", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
var myHeaders = new Headers();
myHeaders.append("x-api-key", "your key");

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://ts-api.somnoon.com/your url", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Java - Unirest

java
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.get("https://ts-api.somnoon.com/your url")
  .header("x-api-key", "your key")
  .asString();
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.get("https://ts-api.somnoon.com/your url")
  .header("x-api-key", "your key")
  .asString();

Golang - Native

go
package main

import (
  "fmt"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://ts-api.somnoon.com/your url"
  method := "GET"

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, nil)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("x-api-key", "your key")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
package main

import (
  "fmt"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://ts-api.somnoon.com/your url"
  method := "GET"

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, nil)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("x-api-key", "your key")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}

C# - HttpClient

c#
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://ts-api.somnoon.com/your url");
request.Headers.Add("x-api-key", "your key");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://ts-api.somnoon.com/your url");
request.Headers.Add("x-api-key", "your key");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

Common request header

The request header parameters defined below are used in each API, where the x-api-key is required

namenecessarytypedefaultdescribe
Accept-Languagefalsestring-语言(language:en_us,zh_cn)
Pagefalsestring-页(page)
Page-Sizefalsestring-页大小(page size)
Sortfalsestring-排序(sort)- id desc
x-api-keytruestring-your key

Common response body

For all requests the JSON format will be returned with the following structure:

json
{
    "code": 0,
    "message": "Success",
    "cause": "",
    "details": {
        // Any response data
    }
}
{
    "code": 0,
    "message": "Success",
    "cause": "",
    "details": {
        // Any response data
    }
}

Other