Skip to content

Authorization

To access the Betting API, you must utilize an X.509 certificate. Please reach out to your integration manager to obtain the necessary certificates and for any additional information.

Check that certificate works

Send request via curl for create demo users token (refer to the Token section for detail).

1
2
3
4
curl --location https://{betting-api-host}/token/create \
     --cert client.crt \
     --key  client.key \
     --data '{"locale": "en", "currency": "EUR"}'
Response
1
2
3
{
  "token": "BRmOHaVLzmJ4_PiYfmWTlEJ3pNNYiM-JCPOQdkvcosixrwdFsV7CXiStzpgWE4n_WfswYN4Bf6BSe6QyaioMI5E1FDmEUqARuQ-4Js5vtVA9WV9fjDoEfq1Pzb1Dk6fnKqOPDRJuXwiBoRvIJsxYSg"
}

Put your client.crt and client.key to the project's directory.

Info

Make sure that you've replaced {betting-api-host} with a correct API host provided by your integration manager.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main

import (
    "bytes"
    "crypto/tls"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    const bettingAPIHost = "{betting-api-host}"

    certificate, err := tls.LoadX509KeyPair("client.crt", "client.key")
    if err != nil {
        panic(fmt.Sprintf("Failed to read X509 key pair: %s", err))
    }

    httpClient := &http.Client{
        Transport: &http.Transport{
            TLSClientConfig: &tls.Config{
                Certificates: []tls.Certificate{certificate},
            },
        },
    }

    type tokenRequest struct {
        Locale   string `json:"locale"`
        Currency string `json:"currency"`
    }

    body, err := createReaderForAny(tokenRequest{
        Locale:   "en",
        Currency: "EUR",
    })
    if err != nil {
        panic(fmt.Sprintf("Failed to create reader: %s", err))
    }

    url := fmt.Sprintf("https://%s/token/create", bettingAPIHost)

    resp, err := httpClient.Post(url, "application/json", body)
    if err != nil {
        panic(fmt.Sprintf("Failed to get response: %s", err))
    }

    data, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(fmt.Sprintf("Failed to read all body: %s", err))
    }

    fmt.Printf("%s\n", resp.Status)
    fmt.Printf("Body:\n%s", data)
}

func createReaderForAny(v any) (io.Reader, error) {
    data, err := json.Marshal(v)
    if err != nil {
        return nil, fmt.Errorf("marshal data: %w", err)
    }

    return bytes.NewBuffer(data), nil
}

1. Prerequisites.

Init new project and add required dependency

1
2
npm init
npm install node-fetch

Make sure that your project type is module.

requirements.json
1
2
3
4
5
6
7
8
{
  ...
  "type": "module",
  "dependencies": {
    "node-fetch": "^3.3.2"
  }
  ...
}

2. Code example

Put your client.crt and client.key to the project's directory.

Put this code into index.js file within a created project.

Info

Make sure that you've replaced {betting-api-host} with a correct API host.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import fetch from 'node-fetch';
import fs from 'node:fs'
import https from 'https';

const bettingAPIHost = '{betting-api-host}'

const response = await fetch(`https://${bettingAPIHost}/token/create`, {
  method: 'POST',
  body: JSON.stringify({
    locale: 'en',
    currency: 'EUR'
  }),
  agent: new https.Agent({
    cert: fs.readFileSync('client.crt'),
    key: fs.readFileSync('client.key'),
  })
});

if (response.ok) {
  console.log(await response.json())
} else {
  console.error(`HTTP Error! Status: ${response.status}. Body: ${await response.text()}`)
}    

3. Run

1
2
3
4
node index.js
{
  token: 'BRmOHaVLzmJ4_PiYfmWTlEJ3pNNYiM-JCPOQdkvcosixrwdFsV7CXiStzpgWE4n_WfswYN4Bf6BSe6QyaioMI5E1FDmEUqARuQ-4Js5vtVA9WV9fjDoEfq1Pzb1Dk6fnKqOPDRJuXwiBoRvIJsxYSg'
}