> For the complete documentation index, see [llms.txt](https://homey.solweb.no/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://homey.solweb.no/custom-integrations/sbanken.md).

# SBanken

Dette homeyscriptet vil bruke sbankens API for å hente ut kontostatus.

Det du må gjøre er å registrere en klient i sbanken beta utvikler portal. Sette fødselsnummer i koden under som customerID. Så må du bruke API-et for å hente ut en account ID for den kontoen du vil ha status for.

{% code title="sbanken.js" %}

```javascript
let customerId = 'xxxfødselsnummerxxx'
let b = xxx base64encoded clientid : secret ....'
let tokenEndpoint = 'https://auth.sbanken.no/identityserver/connect/token'

// var basicAuth = btoa(encodeURIComponent(clientid) + ":" + encodeURIComponent(secret));
// console.log("basic ", basicAuth)

const response = await fetch(tokenEndpoint, {
  "headers": {
    "accept": "application/json",
    "authorization": "Basic " + b,
    "content-type": "application/x-www-form-urlencoded; charset=utf-8"
  },
  "body": 'grant_type=client_credentials',
  "method": "POST"
});
let data = await response.json()
var token = data['access_token']

async function getAPI(path) {
    const baseURL = 'https://api.sbanken.no/exec.bank/api/v1'
    let resp = await fetch(baseURL + path, {
        "headers": {
            "accept": "application/json",
            "authorization": "Bearer " + token,
            "content-type": "application/json",
            "customerId": customerId
        },
        "method": "GET"
    });
    let data = await resp.json()
    return data
}

// Note.. You have to play with the API in postman to get the account ID that you would like to get status from

let r = await getAPI('/Accounts/xxx_accountid_xxx')
console.log("=== Results ===")
console.log(r)

await setTagValue("sbanken_linnea", {type: 'number', title:'Linnea konto'}, r.item.available)

//console.log("response", data)

```

{% 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://homey.solweb.no/custom-integrations/sbanken.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.
