API functions
getPaymentIssues
The getPaymentIssues
function checks if the user has any subscriptions where the last payment failed or if the users card is about to expire. This information can be used to inform the user to update their payment information
// Get payment issues sesamy.getPaymentIssues();
Returns:
(Promise<array<object>>): An array of payment issue objects
Example:
// Check for payment issues for the current user const paymentIssues = await sesamy.getPaymentIssues();
The payment issues will be returned in the following format:
[{ status: 'EXPIRED', subscriptionId: '', endedAt: '2023-11-23T17:58:53.406', provider: 'stripe' }]
getUserProfile
The getUserProfile
function queries for the profile endpoint for the currents users profile:
// Get user profile sesamy.getUserProfile();
Returns:
(Promise<object|null>): A user profile or null
Example:
// Get the user profile for the current user const userProfile = await sesamy.getUserProfile();
The userProfile will be in the following format
{
"version": 1,
"tz": "Europe/Madrid",
"entity": "Profile",
"email": "name@example.com",
"fullName": "name@example.com",
"picture": "https://s.gravatar.com/avatar/fc7c7179a07fe38c0feebd68c8d54e63?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fma.png",
"created": "2022-06-13T09:48:41.824Z",
"identities": [
{
"source": "auth0",
"profileData": {},
"provider": "auth0",
"userId": "61715b8ebe82f0006ab0613b"
}
],
"email_verified": true,
"externalId": {
"auth0.auth0": "61715b8ebe82f0006ab0613b",
"auth0.email": "63beae22c2ff41bf4309c69c"
},
"modified": "2022-11-15T09:58:12.877Z",
"nickname": "nick",
"userId": "auth0|61715b8ebe82f0006ab0613b",
"lastIdpSync": "2023-01-16T10:19:38.804Z"
}
updateUserProfileContactInfo
The updateUserProfileContactInfo
function updates the contact information from the current user:
// Update contact information sesamy.updateUserProfileContactInfo({ email: USER_EMAIL,// Optional firstName: USER_FIRST_NAME,// Optional lastName: USER_LAST_NAME,// Optional });
Arguments:
- USER_EMAIL (string): The updated contact email of the user.
- USER_FIRST_NAME (string): The updated contact first name of the user.
- USER_LAST_NAME (string): The updated contact last name of the user.
Returns:
Example:
// Update the contact information of the current user await sesamy.updateUserProfileContactInfo({ email: "jondoe@example.com", firstName: "Jon", lastName: "Doe", });
updateUserAddress
The updateUserAddress
function updates the billing address from the current vendor user:
// Update contact information sesamy.updateUserAddress({ firstName: USER_ADDRESS_FIRST_NAME,// Optional lastName: USER_ADDRESS_LAST_NAME,// Optional co: USER_ADDRESS_CO,// Optional city: USER_ADDRESS_CITY, street: USER_ADDRESS_STREET, country: USER_ADDRESS_COUNTRY, zip: USER_ADDRESS_ZIP, });
Arguments:
- USER_ADDRESS_FIRST_NAME (string): The updated first name of the vendor user.
- USER_ADDRESS_LAST_NAME (string): The updated last name of the vendor user.
- USER_ADDRESS_CO (string): The updated c/o (care of) of the vendor user.
- USER_ADDRESS_CITY (string): The city of the vendor user.
- USER_ADDRESS_STREET (string): The updated street of the vendor user.
- USER_ADDRESS_COUNTRY (string): The updated country of the vendor user.
- USER_ADDRESS_ZIP (string): The updated zip code of the vendor user.
Returns:
Example:
// Update the billing address of the current vendor user await sesamy.updateUserAddress({ firstName: "Jon", lastName: "Doe", street: "Av. Vallcarca 18, 4, 1A", country: "ES", zip: "08023", });
getEntitlement
The getEntitlement
function queries for the entitlement object that defines the customers access to the content:
// Get entitlment sesamy.getEntitlement(ARTICLE_SRC_OR_SKU, PASSES_ARRAY);
Arguments:
- ARTICLE_SRC_OR_SKU (string): The url or sku for the content
- PASSES_ARRAY (array|undefined): An array of the passes that the content are part of
Returns:
(Promise<object|undefined>): An entitlement or a signedURL object
Example:
// Get the entitlement for an article const entitlement = sesamy.getEntitlement("https://example.com/article", [ "https://example.com/subscription", ]);
getEntitlements
The getEntitlements
function return all the users entitlements. The list is cached in the client for one hours.
// Get entitlments sesamy.getEntitlements();
Returns:
(Promise<array<object>): An array of entitlements and signedURL object
Example:
// Get users entitlements const entitlement = sesamy.getEntitlements();
getSubscriptions
The getSubscriptions
function queries for the subscriptions of the current user:
// Get subscriptions sesamy.getSubscriptions();
Arguments:
Returns:
(Promise<[]>): An array of the subscriptions
Example:
// Get the subscriptions for the current user const subscriptions = await sesamy.getSubscriptions();
The subscriptions will be in the following format
[
{
"id": "test_id",
"userId": "google-oauth2|test",
"currency": "sek",
"cancelAt": 1687532004,
"cancelAtPeriodEnd": true,
"canceledAt": 1684853728,
"created": 1684853604,
"currentPeriodEnd": 1687532004,
"currentPeriodStart": 1684853604,
"endedAt": null,
"checkoutId": "test-3d31-40cc-bb71-9dfe08992e78",
"interval": "month",
"amount": 9900,
"status": "active",
"manageUrl": "https://account.sesamy.dev/sv/subscriptions/kvartal/CH-test-3d31-40cc-bb71-9dfe08992e78",
"product": {
"name": "Montly subscription",
"description": " 99 kr per month w/taxes included",
"distributorId": "sesamy",
"optionId": "test-option-id",
"productId": "sid:test",
"sku": "sid:test",
"vendorId": "test-vendor",
"image": "https://images.sesamy.dev/cover/test/monthly-sub.png"
}
}
]
cancelSubscription
The cancelSubscription
function cancel a subscription from the current user:
// Get subscriptions sesamy.cancelSubscription(SUBSCRIPTION_ID);
Arguments:
- SUBSCRIPTION_ID (string): The id of the subscription to cancel.
Returns:
Example:
// Cancel the subscription for the current user const subscriptions = await sesamy.cancelSubscription("test-id");
getTransactions
The getTransactions
function queries for the transactions of the current user:
// Get transactions sesamy.getTransactions();
Arguments:
Returns:
(Promise<[]>): An array of the transactions
Example:
// Get the transactions for the current user const transactions = await sesamy.getTransactions();
The transactions will be in the following format
[
{
"id": "test-id",
"checkKey": "test-aaa8-404d-89c8-checkkey",
"currency": "SEK",
"totalPrice": 9900,
"items": [
{
"vendorId": "test-vendor",
"title": "Monthly subscription",
"cover": "https://images.sesamy.dev/cover/test/monthly-sub.png",
"price": {
"total": 9900
},
"sku": "sid:test",
"productType": "bundle"
}
],
"modified": "2023-05-23T14:53:30.552Z"
}
]
getAccess
The getAccess
function returns an url to access a content resource, for instance an article or a podcast feed:
// Get access url sesamy.getAccess(ARTICLE_SRC_OR_SKU, PASSES_ARRAY, FORMAT);
Arguments:
- ARTICLE_SRC_OR_SKU (string): The url or sku for the content
- PASSES_ARRAY (array|undefined): An array of the passes that the content are part of
- FORMAT (URL|RSS): The requested format of the access link
Returns:
(Promise<string|undefined>): An url to access the content
Example:
// Get the access url const accessUrl = sesamy.getEntitlement("sid:A2-3YbkzKvJLT8KVJsNZL", [], "RSS");
isLoggedIn
The isLoggedIn
function returns if the user currently is logged in with a valid session:
// Check if a user is logged in. Returns a Promise<boolean> sesamy.isLoggedIn();
Arguments:
Returns:
(Promise<boolean>): The logged in state
Example:
// Get if the user is logged int sesamy.isLoggedIn().then((result) => console.log(result));
login
The login
function redirects the user to the login page.
Arguments:
- forceLogout (optional): if any existing session should be logged out before the login flow is started. Defaults to false
- returnTo (optional): where the user should be redirected after the login flow. Defaults to window.location.href
- email (optional): initiate the login flow with an email and initiate the login flow on the code page.
- scope (optional): specify the scopes requested for the user
- attributes (optional): logs a user into the application using a set of attributes (settings, tags, userMetadata).
- clientId (optional): overrides the client id specified on the page
- organization (optional): specify a organization for the page
Returns:
Example:
// Redirect the user to the login page sesamy.login(); // Attach settings, tags, and user metadata to the user after the login const userAttributes = { tags: ['subscriber', 'political_news_fan'], userMetadata: { age: 45, gender: 'f' }, settings: { firstName: 'Erik', lastName: 'Svensson', allowMailCommunication: true, addresses: [ { firstName: 'Erik', lastName: 'Svensson', city: 'Stockholm', co: '', street: 'Vasagatan 15', zip: '111 20', country: 'Sweden' }, ] } }; sesamy.login(false, undefined, undefined, undefined, userAttributes);
logout
The logout
function clears the user session and bounces the user to the Sesamy logout page to clear the cookie there as well.
Arguments:
Returns:
Redirect the user to the logout page
Example:
// Logout user sesamy.logout();
openCheckout
The openCheckout
function generates a checkout url and redirects the user to the checkout page:
// Open checkout sesamy.openCheckout({ itemSrc: ITEM_SRC_OR_SKU, checkoutVersion: CHECKOUT_VERSION,// Optional publisherContentId: PUBLISHER_CONTENT_ID,// Optional price: PRICE,// Optional currency: CURRENCY,// Optional gift: BOOLEAN; // Optional, default to false discountCode: STRING; // Optional utmSource: UTM_SOURCE;// Optional utmMedium: UTM_MEDIUM;// Optional utmCampaign: UTM_CAMPAIGN;// Optional utmTerm: UTM_TERM;// Optional utmContent: UTM_CONTENT;// Optional
Arguments:
- ITEM_SRC_OR_SKU (string): The url or sku for the content
- CHECKOUT_VERSION (string): The checkout version to use
- PUBLISHER_CONTENT_ID (string): The publisher content id
- PRICE (number): The price of the item
- CURRENCY (string): The currency of the item
- GIFT (boolean): If the checkout should use the gift flow.
- DISCOUNT_CODE (string): The discount code applied to the checkout
- UTM_SOURCE (string): The source UTM tag
- UTM_MEDIUM (string): The medium UTM tag
- UTM_CAMPAIGN (string): The campaign UTM tag
- UTM_TERM (string): The term UTM tag
- UTM_CONTENT (string): The content UTM tag
Returns:
Redirects the user to the checkout page
Example:
// Open a checkout for an article sesamy.openCheckout({ itemSrc: "https://example.com/article", checkoutVersion: "2", publisherContentId: "article-1", price: 100, currency: "SEK", discountCode: "DISC50", utmSource: "google", utmMedium: "cpc", utmCampaign: "sale", utmTerm: "article", utmContent: "ad", });
If the product uses a purchase option this is appended to the itemSrc attribute with a :
as a separator:
sesamy.openCheckout({ itemSrc: "https://example.com/article:option-1", checkoutVersion: "2", publisherContentId: "article-1", price: 100, currency: "SEK", });
parsePodcast
The parsePodcast
function parses a podcast using the url to feed an returns it in a json format:
// Open checkout sesamy.parsePodcast(FEED_URL);
Arguments:
- FEED_URL (string): The url to a podcast feed
Returns:
A podcast with episodes in a json format
{
"title": "Åh fan! - Premium",
"externalIds": {},
"description": ".",
"summary": ".",
"image": "https://assets.example.com/system/shows/images/eb5/efa/53-/large/fokus-podden.png",
"author": "Fokus Redaktion",
"owner": {
"name": "Fokus Redaktion",
"email": "redaktion@fokus.se"
},
"publishDate": "2023-05-29T12:17:49.000Z",
"language": "en",
"keywords": [],
"rssUrl": "https://feed.sesamy.com/sid:2QNn9E1brlrKDGAf-lOY-",
"copyright": "Sesamy AB",
"isHidden": false,
"isExplicit": false,
"isComplete": false,
"podcastType": "EPISODIC",
"totalSeasons": 0,
"totalEpisodes": 1,
"episodes": [
{
"guid": "94d2db0ef890140723600cf8cd4ec89c",
"title": "Test",
"subtitle": "",
"description": "",
"url": "https://media.example.com/ahfanpremium/fokuspodden_211020_mix01.mp3",
"link": "https://sesamy.com/products/sid:2QNn9E1brlrKDGAf-lOY-?guid=94d2db0ef890140723600cf8cd4ec89c",
"image": "https://assets.example.com/system/shows/images/eb5/efa/53-/large/fokus-podden.png",
"duration": 2819,
"isExplicit": false,
"episodeType": "full",
"contentType": "audio/mpeg",
"contentLength": 45119702,
"publishDate": "2023-05-29T12:17:49.000Z",
"isLocked": false,
"isSesamy": false,
"isSample": false,
"permissions": []
}
],
"products": [],
"categories": [],
"sesamy": {
"vendorId": "test-fokus",
"isPrivate": false
}
}
Example:
// Open a checkout for an article sesamy.parsePodcast("https://feed.sesamy.com/sid:2QNn9E1brlrKDGAf-lOY-");
getFulfillmentProductItems
The getFulfillmentProductItems
function returns all the issues from a publication:
// Get issues from a publicaction sesamy.getFulfillmentProductItems(PUBLICATION_SKU);
Arguments:
- PUBLICATION_SKU (string): The sku of the publication.
Returns:
A count of the items and an items array with the publication’s issues in a json format:
{
"count": 1,
"items": [
{
"content": {
"id": "url:59c1dfed5d09543c35fd84edd438a1eb-url",
"type": "url",
"title": "Bundle URL",
"url": "https://fokus.test"
},
"userEmail": "ignasi@sesamy.com",
"status": "FAILED_DELIVERY",
"deliveryProvider": "earlybird",
"vendorId": "test-fokus",
"cover": "\t https://assets.sesamy.com/vendors/fokus/fokus-bundle.jpg",
"itemId": "cea4e486a01644a02d11176eee304211",
"entity": "FulfillmentItem",
"createdAt": "2023-11-28T17:51:42.235Z",
"userLastName": "Test User Last Name",
"userPicture": "https://lh3.googleusercontent.com/a/ACg8ocLH7pzYCYDpsEchKBsHN78-hxWaOLApFRvLOxjCFESRMg=s96-c",
"modifiedAt": "2023-11-29T10:59:54.867Z",
"userId": "google-oauth2|115217541378154697444",
"itemSourceProvider": "stibo",
"userFirstName": "Test User First Name",
"deliveryAddress": {
"zip": "08023",
"country": "ES",
"lastName": "Test User Last Name",
"firstName": "Test User First Name",
"city": "Barcelona",
"street": "Vallcarca 18",
"co": ""
},
"entitlementId": "811889c277be16d5b2f446c48ad9657a",
"parentSku": "sid:JleF1H8L-dZwNw744Pc2M",
"sku": "sid:AleF1H8L-dZwNw744Pc2B",
"title": "Physical product issue 1."
}
]
}
}
Example:
// Get the issues for a publication const issues = await sesamy.getFulfillmentProductItems("sid:JleF1H8L-dZwNw744Pc2M");
requestFulfillmentProductItem
The requestFulfillmentProductItem
makes a request for the logged-in user that haven’t received an issue of a publication:
// Makes a request for a not delivered issue sesamy.requestFulfillmentProductItem(ISSUE_SKU, ITEM_ID);
Arguments:
- ISSUE_SKU (string): The sku of the issue.
- ITEM_ID (string): The id of the item to make the complaint request.
Returns:
If the request succeeds you get an object with an updateId and the details of the update request.
{ "userId": "google-oauth2|115217541378154697444", "updateType": "USER_NOT_RECEIVED_COMPLAIN", "updateEffect": "THIS_ITEM", "updateTime": "2023-11-29T13:30:22.008Z", "fulfillmentItemId": "cea4e486a01644a02d11176eee304211", "updateId": "3ff0191d-8224-424b-8fed-af5d6f754dc1", "notes": "", "updates": {} }
Example:
// Get the issues for a publication const response = await sesamy.requestFulfillmentProductItem("sid:AleF1H8L-dZwNw744Pc2B", "cea4e486a01644a02d11176eee304211")
updateFulfillmentProductItemAddress
The updateFulfillmentProductItemAddress
makes a delivery address update request for a user:
// Makes a request for a not delivered issue sesamy.updateFulfillmentProductItemAddress( ISSUE_SKU, ITEM_ID, DELIVERY_ADDRESS, UPDATE_EFFECT // Optional );
Arguments:
- ISSUE_SKU (string): The sku of the issue.
- ITEM_ID (string): The id of the item to make the complaint request.
- DELIVERY_ADDRESS (object): The updated delivery address.
- UPDATE_EFFECT (THIS_ITEM | FOREVER): Apply the change only for the desired issue or for the desired issue and the following ones as well.
Returns:
If the request succeeds you will get an object with an updateId and the details of the update request.
{ "userId": "google-oauth2|115217541378154697444", "updateType": "USER_ADDRESS_UPDATE", "updateEffect": "THIS_ITEM", "updateTime": "2023-11-29T13:40:29.437Z", "fulfillmentItemId": "cea4e486a01644a02d11176eee304211", "updateId": "32d96e14-3361-4116-ad73-0291a0d08bf8", "notes": "", "updates": { "previousDeliveryAddress": { "zip": "10316", "country": "SE", "lastName": "Test", "firstName": "Julian", "city": "Stockholm", "street": "Test 123", "co": "" }, "newDeliveryAddress": { "country": "ES", "zip": "08023", "city": "Barcelona", "street": "Vallcarca 18", "co": "", "lastName": "Test User Last Name", "firstName": "Test User First Name" } } }
Example:
// Get the issues for a publication const response = await sesamy.updateFulfillmentProductItemAddress("sid:AleF1H8L-dZwNw744Pc2B", "cea4e486a01644a02d11176eee304211", { country: "ES", zip: "08023", city: "Barcelona", street: "Vallcarca 18", co: "", lastName: "Test User Last Name", firstName: "Test User First Name" })
version
The version
function returns the current version of the Sesamy javascript api
Arguments:
Returns:
Version number
Example:
// Get version sesamy.version();
setAttribution
The attribution information keeps track utm-tags and of the last article viewed before a conversion. When using the content-container component this is handled automatically but it’s also possible to set it manually using the setAttribution
function:
// Set an article as itemSrc attribution sesamy.setAttribution({ itemSrc: 'https://example.com/article' });
Arguments:
itemSrc?: string;
publisherContentId?: string;
ref?: string;
referrer?: string;
utm_source?: string;
utm_medium?: string;
utm_campaign?: string;
utm_content?: string;
utm_term?: string;
setToken
The setToken is used to provide an accessToken via the api instead of the built-in login flows. It can for instance be used in React Native apps, where the authentication is handled in the native part of the application and needs to be passed to a Web View.
The setToken does not accept a refresh token, so the user will be logged out when the token expires
// Set the access token sesamy.setToken('eyJraWQiOiJZdjdFdFNWal...' });