The url format is as follows:
https://spreedly.com/api/[api_version]/[site]/[call]
where :api_version is currently “v3”. Using the version in the url allows us to enhance and modify the API without breaking your usage of the site. Then you can use the new version when you choose. The :site is either “production” or “test”, depending on which site you’d like to hit.
[ ~ ] $ curl https://spreedly.com/api/v3/production/subscribers/7388.xml
HTTP Basic: Access denied.
Notice that access was denied. We’re actually returning a 401 status code (Unauthorized). You can see the status code returned in curl using the -v command line switch. Now let’s try with our username and a password of X:
[ ~ ] $ curl -u duff:X https://spreedly.com/api/v3/production/subscribers/7388.xml
HTTP Basic: Access denied.
Access denied again. In order to access the api, you need to obtain your API authentication token, which you can see on your account page.
When you use this token, simple XML is returned. Notice that a password is not necessary here. I specified an ‘X’ because it’s often easier to do that since many clients require a password. Spreedly ignores this password for API calls.
[ ~ ] $ curl -u cbb8f088775cf209035729c0eb69b9f340a3b047:X https://spreedly.com/api/v3/production/subscribers/7388.xml
Here is the response:
<?xml version="1.0" encoding="UTF-8"?>
<subscriber>
<active type="boolean">true</active>
<active-until type="datetime">2008-02-21T19:04:28Z</active-until>
<billing-first-name>Super</billing-first-name>
<billing-last-name>Jim</billing-last-name>
<card-expires-before-next-auto-renew type="boolean">false</card-expires-before-next-auto-renew>
<created-at type="datetime">2007-12-21T18:54:24Z</created-at>
<customer-id>7388</customer-id>
<eligible-for-free-trial type="boolean">false</eligible-for-free-trial>
<email></email>
<feature_level type="string">Pro</feature_level>
<lifetime-subscription type="boolean">false</lifetime-subscription>
<on_trial type="boolean">false</on_trial>
<recurring type="boolean">false</recurring>
<screen-name>jim-bob</screen-name>
<store-credit type="decimal">0.0</store-credit>
<subscription-plan-name>Super Pro Account</subscription-plan-name>
<token>1c08af7ef78f1a4b51127cf0ddfe7b2b24681b6c</token>
<updated-at type="datetime">2007-12-21T19:04:28Z</updated-at>
</subscriber>
This was a successful call to the API. The status code returned is 200 (OK).
Let’s say you request information about a non-existent subscriber. Spreedly returns a status code of 404 (Not Found) in this case.
Until you implement caching, you’ll just request the url every time you need subscription info.
Return to the Integration Guide ↑
You can also retrieve information about all of the subscribers like so:
[ ~ ] $ curl -u cbb8f088775cf209035729c0eb69b9f340a33042:X https://spreedly.com/api/v3/production/subscribers.xml
Here is the response:
<?xml version="1.0" encoding="UTF-8"?>
<subscribers type="array">
<subscriber>
<active type="boolean">true</active>
<active-until type="datetime">2008-02-21T19:04:28Z</active-until>
<billing-first-name>Super</billing-first-name>
<billing-last-name>Jim</billing-last-name>
<card-expires-before-next-auto-renew type="boolean">false</card-expires-before-next-auto-renew>
<created-at type="datetime">2007-12-21T18:54:24Z</created-at>
<customer-id>7388</customer-id>
<eligible-for-free-trial type="boolean">false</eligible-for-free-trial>
<email></email>
<feature_level type="string">Pro</feature_level>
<lifetime-subscription type="boolean">false</lifetime-subscription>
<on_trial type="boolean">false</on_trial>
<recurring type="boolean">false</recurring>
<screen-name>jim-bob</screen-name>
<store-credit type="decimal">0.0</store-credit>
<subscription-plan-name>Super Pro Account</subscription-plan-name>
<token>1c08af7ef78f1a4b51127cf0ddfe7b2b24681b6c</token>
<updated-at type="datetime">2007-12-21T19:04:28Z</updated-at>
</subscriber>
</subscribers>