Authenticating with cURL


The Subscribe Pro API allows developers to manage their subscription, customer, and payment profile information remotely. Authentication to the API requires a Client ID and Client Secret, both of which can be found on your Subscribe Pro Environment. Visit System -> API Clients and click the View button on the far right of the table to see both credentials.

Once you have both the Client ID and Client Secret, you have what you need to authenticate to the Subscribe Pro API. There are two ways to do so. One involves sending an initial call to Subscribe Pro to retrieve an access token, which will be used in all other calls. For this method you will need your Client ID and Client Secret only for the first authentication call. The access token will expire after a certain amount of time (this information is sent in the response data) so you will need to retrieve another access token after that time to continue making calls to Subscribe Pro.

The second method allows you to make calls to the API without the access token by sending the Client ID and Client Secret with each API call as the basic HTTP Authentication username and password.

Access Token Authentication

Open a shell terminal with curl installed, and type the following command. Substitute "<clientid>" and "<clientsecret>" with their respective values.

curl https://api.subscribepro.com/oauth/v2/token -d 'grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>'

You should get the following response:

{
  "access_token": "<access_token>",
  "expires_in": 3600,
  "token_type": "bearer",
  "scope": null,
  "refresh_token": "<refresh_token>"
}

If the credentials were incorrect, you will get the following response:

{
  "error": "invalid_client",
  "error_description": "The client credentials are invalid"
}

In the above, "<access_token>" is an 86-character, alpha-numeric string that can then be used to perform other operations on your Subscribe Pro Environment. It will expire after 3600 seconds (one hour).

As an example, if you wanted to get all of the subscriptions a specific customer has in your Subscribe Pro Environment, you can use the "/services/v2/subscriptions.{_format}" endpoint. {_format} can be one of "xml", "json", and "html". Below, "<customer_id>" is a number corresponding to the Customer ID in Subscribe Pro.

curl https://api.subscribepro.com/services/v2/subscriptions.json?access_token=<access_token>&customer_id=<customer_id>

This will return a JSON-encoded list of all subscriptions associated with that customer.

Basic HTTP Authentication

Open a shell terminal with curl installed, and type the following command. Substitute "<clientid>" and "<clientsecret>" with their respective values. The following command will fetch a JSON-encoded array of data about all subscriptions for the given customer ID.

curl --user <client_id>:<client_secret> https://api.subscribepro.com/services/v2/subscriptions.json?customer_id=<customer_id>

This will return a JSON-encoded list of all subscriptions associated with that customer.

To view information about all of the things that can be done using our API, view our documentation here.