File: //home/arjun/projects/buyercall/buyercall/blueprints/user/templates/user/rest_api.jinja2
{% extends 'layouts/backend_old.jinja2' %}
{% block title %}REST API information{% endblock %}
{% block heading %} REST API Settings {% endblock %}
{% block body %}
<div class="content-alt">
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="card">
<div class="card-header card-header-icon" data-background-color="light-blue">
<i class="material-icons">open_in_browser</i>
</div>
<div class="card-content">
<h4 class="card-title">Generate New Authentication Token
</h4>
<div class="row">
<div class="col-md-12">
<p>The buyercall REST API allows you to access your calls data using
your own applications, through a JSON HTTP interface, as specified in
<a href="https://tools.ietf.org/html/rfc6750">RFC6750</a>.</p>
<p>To access the API securely, you need to generate a bearer token, if you
haven't done this before.<br/>
<br />
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<i class="material-icons">close</i>
</button>
<span>
<b> Warning - </b> You will not be able to access your authentication token again
after viewing it below. Please make sure to save this token somewhere save for any
future use. If you forgot your token please generate a new token below.</span>
</div>
</p>
<form method="post" action="{{ url_for('.rest_api_update') }}">
<div class="form-group">
<input type="hidden" name="_csrf_token" value="{{ csrf_token() }}" />
<h4>Generate new authentication token:</h4>
<div class="input-group">
<input name="token" readonly onclick="this.select()"
{% if generated %}placeholder="Overwriting old token."{% endif %}
value="{{ token }}"
class="form-control" />
<span class="input-group-btn">
<button class="btn btn-fill btn-light-blue" type="submit">
Generate</button>
</span>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="card">
<div class="card-header card-header-icon" data-background-color="light-blue">
<i class="material-icons">library_books</i>
</div>
<div class="card-content">
<h4 class="card-title">REST API Documentation
</h4>
{% if current_user.role == 'partner' %}
<div class="row">
<div class="col-md-12">
<p>The current BuyerCall Partner API version is in 2.0. All API endpoint documentation
for the BuyerCall Partner API can be <a href="{{ url_for('api_doc.api_doc_view') }}">found here.</a></p>
<p>
</div>
</div>
{% else %}
<div class="row">
<div class="col-md-12">
<p>Use the REST API by sending a GET request to the <code>/api/v1/calls</code> endpoint of the buyercall site, providing the authorization token as an HTTP header.</p>
<p>For example, to test the API from the command-line - assuming your authorization token is <code>74fc9d2d-5c39-47cd-8551-1bd73d50cf5e</code>, try entering the following in a Unix command line:</p>
<p>
<kbd>curl -H "Authorize: Bearer 74fc9d2d-5c39-47cd-8551-1bd73d50cf5e" https://buyercall.com/api/v1/calls</kbd>
</p>
<p>The result should look something like:
<pre style="color: white">
{
"calls": [
{
"id": 538,
"firstname": "Erik",
"lastname": "Mustermann",
"call_count": 0,
"duration": null,
"email": "erikm@example.com",
"phonenumber": "+1 (456) 555-1234",
"question": "Is the 2015 Honda still available?",
"starttime": "2016-01-25T17:34:19.440346",
"endtime": null,
"status": "missed",
"recording_url": null,
"notes": "Will try calling him again on Sunday. -- Bob",
"agent": "John Smith",
}
]
}
</pre>
</p>
<p>On unsuccessful authentication, the output might look like:
<pre style="color: white">
HTTP/1.1 401 UNAUTHORIZED
Server: gunicorn/19.3.0
Date: Sun, 15 May 2016 16:36:51 GMT
Connection: close
Content-Type: text/html; charset=utf-8
Content-Length: 21
WWW-Authenticate: Bearer realm="buyercall", error="invalid_token", error_description="Invalid credentials"
Invalid credentials
</pre>
</p>
<p>Similarly, the list of agents, the outbound, and the inbound routings can be retrieved by replacing <kbd>/api/v1/calls</kbd> in the example above with <kbd>/api/v1/agents</kbd>, <kbd>/api/v1/outbound</kbd>, and <kbd>/api/v1/outbound</kbd>, respectively.
</p>
</div>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}