Every repository with this icon (
Every repository with this icon (
Chart API
The Swivel Chart API enables you to easily upload charts, update them automatically, or delete them. The API returns XML responses via a REST interface, and currently supports create, read, update and delete operations for charts.
Note: it may be necessary to replace the UPPERCASE SECTIONS with appropriate text.
Create
Create a CSV file and POST it to the chart create URL on the Swivel API server.
curl -X POST \
-u "YOUR_EMAIL_ADDRESS:YOUR_PASSWORD" \
-F "name=Profit and Revenue" \
-F "data=<profit_and_revenue.csv" \
-k https://api.swivel.com/v1/charts.xml
When you create the chart, the Swivel API will return XML describing it:
<?xml version="1.0" encoding="UTF-8"?>
<chart>
<created-at type="datetime">2009-05-15T17:41:20-07:00</created-at>
<description nil="true"></description>
<group-id type="integer">1</group-id>
<group-writable type="boolean" nil="true"></group-writable>
<id type="integer">CHART_ID</id>
<name>Profit and Revenue</name>
<options nil="true"></options>
<person-id type="integer">1</person-id>
<secret>zbNpCIOEZqqL7KtfRY8imA==</secret>
<title>New chart</title>
<updated-at type="datetime">2009-05-15T17:41:20-07:00</updated-at>
</chart>
Keep track of the CHART_ID of the newly-created chart. You will use it for future API calls.
Read
Your chart will now appear in your Swivel drafts. To read the chart using the API, simply GET its URL:
To get the chart metadata:
curl -u "YOUR_EMAIL_ADDRESS:YOUR_PASSWORD" \
-k https://api.swivel.com/v1/charts/CHART_ID.xml
To get the chart data as a CSV:
curl -u "YOUR_EMAIL_ADDRESS:YOUR_PASSWORD" \
-k https://api.swivel.com/v1/charts/CHART_ID.csv
Update
Create a new CSV file with the same columns as the original, and PUT it to the Swivel Chart API.
To replace the chart data:
curl -X PUT \
-u "YOUR_EMAIL_ADDRESS:YOUR_PASSWORD" \
-F "data=<profit_and_revenue2.csv" \
-k https://api.swivel.com/v1/charts/CHART_ID.xml
To append to the chart data:
curl -X PUT \
-u "YOUR_EMAIL_ADDRESS:YOUR_PASSWORD" \
-F "data=<profit_and_revenue2.csv" \
-F "mode=append" \
-k https://api.swivel.com/v1/charts/CHART_ID.xml
An HTTP header with an “ok” response will be returned if the data is updated.
Delete
Specify which data set you are deleting in the URL as shown.
curl -X DELETE \
-u "YOUR_EMAIL_ADDRESS:YOUR_PASSWORD" \
-k https://api.swivel.com/v1/charts/CHART_ID.xml






