Information about the current subscription is available on the Account
-object under CurrentSubscription.
The most straightforward endpoints to use are the Get account and the Get all accounts.
By default, requests will return all fields from the requested object and its child objects. To return fields from deeper in the object graph, you must explicitly request them via the fields parameter.
For an account's current subscription, the Plan
-object and SubscriptionAddOns
-array must be explicitly expanded, but the StartDate
, for instance, is returned by default.
To get only the information about the current subscription, its plan, and its add-ons configure the field param like so:
?fields=Uid,CurrentSubscription.*,CurrentSubscription.Plan.*,CurrentSubscription.SubscriptionAddOns.*,CurrentSubscription.SubscriptionAddOns.AddOn.*
To get only the information about the current subscription and its plan, configure the field param like so:
?fields=Uid,CurrentSubscription.*,CurrentSubscription.Plan.*
In JavaScript, it would look like the following to get access to the current subscription plan name and start date for the first 20 accounts (as the code does not handle pagination etc):
const fetchResponse = await fetch( `https://${process.env.OUTSETA_SUB_DOMAIN}.outseta.com/api/v1/crm/accounts?fields=Uid,CurrentSubscription.*,CurrentSubscription.Plan.*`, { headers: { Authorization: `Outseta ${process.env.OUTSETA_API_KEY}:${process.env.OUTSETA_API_SECRET}`, }, }, ); if (!fetchResponse.ok) throw new Error("Response not ok"); const data = await fetchResponse.json(); data.items.forEach((item) => { if (item.CurrentSubscription) { console.log( `Account ${item.Uid} with plan ${item.CurrentSubscription.Plan.Name} started ${item.CurrentSubscription.StartDate}`, ); } else { console.log(`Account ${item.Uid} has no current subscription`); } });
If you start from the Person
-object another two levels are added to the object graph. This would be the case when using the Get person or Get all people endpoint for instance.
To then get the information about the current subscription and its plan, configure the field param like so:
?fields=Uid,Email,PersonAccount.*,PersonAccount.Account.*,PersonAccount.Account.Subscriptions.*,PersonAccount.Account.Subscriptions.Plan.*
In JavaScript, it would then look like the following to get access to the current subscription plan name and start date for the first 20 accounts (as the code does not handle pagination etc):
const fetchResponse = await fetch( `https://${process.env.OUTSETA_SUB_DOMAIN}.outseta.com/api/v1/crm/people?fields=Uid,Email,PersonAccount.Account,PersonAccount.Account.Uid,PersonAccount.Account.CurrentSubscription.*,PersonAccount.Account.CurrentSubscription.Plan.*`, { headers: { Authorization: `Outseta ${process.env.OUTSETA_API_KEY}:${process.env.OUTSETA_API_SECRET}`, }, }, ); if (!fetchResponse.ok) throw new Error("Response not ok"); const data = await fetchResponse.json(); data.items.forEach((person) => { // PS: A person may belong to more than one account console.log( `Person ${person.Uid}-${person.Email} belongs to ${person.PersonAccount.length} accounts:`, ); person.PersonAccount.forEach((personAccount) => { if (personAccount.Account.CurrentSubscription) { console.log( `- Account ${personAccount.Account.Uid} with plan ${personAccount.Account.CurrentSubscription.Plan.Name} started ${personAccount.Account.CurrentSubscription.StartDate}`, ); } else { console.log( `- Account ${personAccount.Account.Uid} has no current subscription`, ); } }); });