{% include 'includes/header.html' %}

<h2 class='title'>API v1.0 Documentation</h2>


You can interact with the agent using a RESTful API. This API gives you full access to the agent and its data.

<h4 class='endpoint_documentation'>Variables</h3>

When reading this documentation you will find variables in two forms:

<ul>
  <li class='argument_element'><em class='argument'>&ltvariable&gt:</em> Variables that are between &lt&gt have to be replaced by their values in the URL. For example, <code>/api/v1.0/variables/categories/&ltcategory&gt</code> will turn into <code>/api/v1.0/variables/categories/my_category</code>.</li>
  <li class='argument_element'><em class='argument'>variable:</em> Variables that are NOT enclosed by &lt&gt:
    <ul>
      <li class='argument_element'>If the method is a GET variables that are between &lt&gt have to be replaced by their values in the URL. For example, <code>/api/v1.0/variables/categories/&ltcategory&gt</code> will turn into <code>/api/v1.0/variables/categories/my_category</code>.</li>
      <li class='argument_element'>If the method is a POST or a PUT variables variables that are between &lt&gt have to sent as a JSON object.</li>
    </ul></li>
</ul>

<h4 class='endpoint_documentation'>Responses</h3>

All the responses from the agent will be in JSON format and will include three sections:

<ul>
  <li><em>meta</em>: Metainformation about the response. For example, request_time, length of the response or if there was any error.</li>
  <li><em>parameters</em>: The parameters used for the call.</li>
  <li><em>result</em>: The result of the call or a description of the error if there was any.</li>
</ul>

For example, for the following call you will get the following response:

<pre><code>/api/v1.0/analytics/top_prefixes?limit_prefixes=10&start_time=2015-07-13T14:00&end_time=2015-07-14T14:00&net_masks=20,24</code></pre>
<pre><code class="json">
  {
    "meta": {
      "error": false,
      "length": 10,
      "request_time": 11.99163
    },
    "parameters": {
      "end_time": "2015-07-14T14:00",
      "exclude_net_masks": false,
      "limit_prefixes": 10,
      "net_masks": "20,24",
      "start_time": "2015-07-13T14:00"
    },
    "result": [
      {
        "as_dst": 43650,
        "key": "194.14.177.0/24",
        "sum_bytes": 650537594
      },
      ...
      {
        "as_dst": 197301,
        "key": "80.71.128.0/20",
        "sum_bytes": 5106731
      }
    ]
  }</code></pre>

{% for section, endpoints in documentation.iteritems() %}

<h3 class='title'>{{ section }} Endpoint</h3>

  {% for endpoint in endpoints %}
<h4 class='endpoint_documentation'>{{ endpoint['endpoint']}}</h4>

    {% for method in endpoint['methods'] %}
<h5 class='endpoint_documentation'>{{method['method']}}</h5>

<em class='endpoint_documentation'>Description:</em>

<div class='endpoint_documentation'>
{{ method['description']|safe }}
</div>

<em class='endpoint_documentation'>Arguments:</em>
<ul class='endpoint_documentation'>
      {% for key, value in method['arguments'].iteritems() %}
    <li class='argument_element'><em class='argument'>{{key}}:</em> {{value}}
    </li>
      {% endfor %}
</ul>

<em class='endpoint_documentation'>Returns:</em>
<ul class='endpoint_documentation'>
    <li class='argument_element'>{{method['returns']}}</li>
</ul>

<em class='endpoint_documentation'>Examples:</em>
<ul class='endpoint_documentation'>
      {% for example in method['examples'] %}
    <li class='argument_element'>http://127.0.0.1:5000{{ endpoint['endpoint'] }}{{example}}
    </li>
      {% endfor %}
</ul>


    {% endfor %}

  {% endfor %}


{% endfor %}

{% include 'includes/footer.html' %}
