# get_balance

Returns the bot’s avatar L$ balance.

```csharp
string params = llDumpList2String([
  "action="  + "get_balance",
  "apikey="  + llEscapeURL(sbApiKey),
  "botname=" + llEscapeURL(sbBotName),
  "secret="  + llEscapeURL(sbBotApiToken)
], "&");

httpReq = llHTTPRequest("https://api.mysmartbots.com/api/bot.html", [HTTP_METHOD,"POST"], params);
```

```snippet http-api-variables-OmJyUigTgO
```

```snippet http-api-input-basic-parameters-5FcVlaJbq0 action="get_balance"
```

## Input

This command has **no additional input parameters**.

```snippet http-api-output-JAwUcmg7i7
balance | The L$ balance of the bot
```

# Example

This example script requests the bot's avatar balance from LSL and demonstrates how to parse HTTP API replies using the `get_post_value` function.

```csharp
string sbApiKey = "...";
string sbBotName = "OneSmartBot Resident";
string sbBotApiToken = "...";

key httpReq = NULL_KEY;

// Get posted data's value.
string get_post_value(string content, string returns) {
    list params = llParseString2List(content, ["&"], []);
    integer index = ~llGetListLength(params);
    list keys;
    list values;

    while (++index) {
        list parsedParams = llParseString2List(llList2String(params, index), ["="], []);
        keys += llUnescapeURL(llList2String(parsedParams, 0));
        values += llUnescapeURL(llList2String(parsedParams, 1));
    }

    integer found = llListFindList(keys, [returns]);
    if (~found) {
        return llList2String(values, found);
    } else {
        return "";
    }
}

default {
    touch_start(integer total_number) {
        if (llDetectedKey(0) != llGetOwner()) {
            llInstantMessage(llDetectedKey(0), "Only my owner can use me!");
            return;
        }

        string params = llDumpList2String([
            "action="  + "get_balance",
            "apikey="  + llEscapeURL(sbApiKey),
            "botname=" + llEscapeURL(sbBotName),
            "secret="  + llEscapeURL(sbBotApiToken)
        ], "&");

        httpReq = llHTTPRequest("https://api.mysmartbots.com/api/bot.html",
            [HTTP_METHOD, "POST"], params);
    }

    http_response(key request_id, integer status, list metadata, string body) {
        if (request_id != httpReq) return;

        string action     = get_post_value(body, "action");
        string result     = get_post_value(body, "result");
        string resulttext = get_post_value(body, "resulttext");
        string balance    = get_post_value(body, "balance");

        if (result == "FAIL") {
            llOwnerSay("Command '" + action + "' failed: " + resulttext);
        } else {
            llOwnerSay("Your bot's balance is L$" + balance);
        }
    }
}
```