Example Requests 💡

All example requests on this page are contained in the example project.

Queries

Get the username and contracts

After successfully connecting the bank account, the overview screen shows the entered username and the detected contracts.

This request was used to get the overview data:

 request(
        GraphQlBody(
                query = getQuery(Queries.Overview.filename),
                variables = mapOf(
                        Pair("language", LANGUAGE_DE)
                )
        ),
        object : TypeToken<ValuePage<User>>() {}.type
)

The request above loads the overview-Query from the file system and sends it to the Yoli API. As you might have noticed you send the desired language as a variable alongside the request. This is needed since the category of a Contract is a so called Translatable. It maps directly in the language you need in your Client. Below the GraphQlBody we instanciate a generic TypeToken. This TypeToken defines the result of the request as an instance of the User class.

The overview-Query looks like this:

fun getOverviewDataRx(): Observable<GraphQlPage<ValuePage<User>>> {
    query getOverview($language: String!) {
        value: me {
            username
            contracts {
                contractid
                amount
                contractPartner {
                name
                }
                mainCategory {
                id
                text(lang: $language)
                }
            }
        }
    }
}

Bank Login Status

Since the bank login process can take some time, especially when the user has a lot of transactions, we provide an endpoint to add the bank account (described below) which responses with a so called bank login task token. This token can be used to request the status of the bank login process.

The request implementation looks like this:

fun getLoginStatusRx(token: String): Observable<GraphQlPage<ValuePage<BankLoginStatus>>> {
    return request(
            GraphQlBody(
                    query = getQuery(Queries.BANK_LOGIN_STATUS.filename),
                    variables = mapOf(
                            Pair("token", token)
                    )
            ),
            object : TypeToken<ValuePage<BankLoginStatus>>() {}.type
    )
}

The request above loads the bank_login_status-Query from the file system and sends it to the Yoli API. Because we want to get informationen about a specific login status, we send the variable token to the API, like we did with the language variable above. Beside the GraphQlBody we define with the generic TypeToken that the result should be an instance of the BankLoginStatus class.

The bank_login_status-Query looks like this:

query BankLoginStatus($token: String!) {
  value: bankLoginStatus(taskToken: $token) {
      status
      message
   }
}

Mutations

Create a new User

You can create a user via the createMe endpoint from the API. Please note that this is the only request in this example page where an authorizedRequest isn't needed. Also we don't need any variables here.

fun createUserRx(): Observable<GraphQlPage<ValuePage<String>>> {
    return request(
            GraphQlBody(
                    query = getQuery(Mutations.CREATE_USER.filename)
            ),
            object : TypeToken<ValuePage<String>>() {}.type,
            false
    )
}

The create_user-Mutation looks like this:

mutation createUser {
  value: createMe
}

Change Username

To change the name of the user you can use the request below. Because this mutation only returns a boolean indicating whether the operation was successful we don't need a custom model.

fun changeNameRx(username: String): Observable<GraphQlPage<ValuePage<Boolean>>> {
    return request(
            GraphQlBody(
                    query = getQuery(Mutations.CHANGE_NAME.filename),
                    variables = mapOf(
                            Pair("username", username)
                    )
            ),
            object : TypeToken<ValuePage<Boolean>>() {}.type
    )
}

The change_name-Mutation looks like this:

mutation changeName($username: String!) {
  value: changeName(username: $username)
}

Add Bank Account

Adding a bank account returns a task token. This task token can be used to request the status via the bankLoginStatus query. To send multiple variables to the Yoli API we just use a Map of values.

fun bankLoginRx(bankCode: String, loginInterface: String, credentials: List<CredentialInput>) : Observable<GraphQlPage<ValuePage<String>>> {
    return request(
            GraphQlBody(
                    query = getQuery(Mutations.BANK_LOGIN.filename),
                    variables = mapOf(
                            Pair("bankCode", bankCode),
                            Pair("credentials", credentials,
                            Pair("interface", loginInterface)
                    )
            ),
            object : TypeToken<ValuePage<String>>() {}.type
    )
}

The bank_login-Mutation looks like this:

mutation addBankLogin($bankCode: String!, $credentials: [CredentialItemInput]!, $interface: String!) {
    value: addBankLogin(bankCode: $bankCode, credentials: $credentials, loginInterface: $interface)
}