Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.3.0: Multiple personal coupons creation endpoint, Loyalty and Referrals counters and Export Endpoints #22

Merged
merged 1 commit into from
Feb 3, 2021

Conversation

altJake
Copy link
Member

@altJake altJake commented Feb 2, 2021

Summary

Management API

Introduce createCouponsForMultipleRecipients Endpoint

An endpoint to allow creation of multiple coupons of the same configuration for up to 1,000 recipients at once.

☝️ Back to Table of Contents

Expose export endpoints as integral part of the SDK

All of our CSV export endpoints are accessible via the Web Application from the corresponding entity pages (refer to our Help Center for an example regarding Coupons).

Now these are also available endpoints as part of the SDK (links to our developer docs):

Example code snippet demonstrating consuming and printing the lines of a Customer Loyalty Balance Export using the csv-parse package:

const TalonOne = require('talon_one')
const csvParse = require('csv-parse')

// ...preparing api client...
// An example could be seen at the repository's README file: https://github.com/talon-one/talon_one.js#management-api

managerApi.exportLoyaltyBalance('1')
  .then((data) => {
    return new Promise((resolve, reject) => {
      csvParse(data, {
        columns: true,
        skipEmptyLines: true,
      }, (err, output) => {
        if (err) {
          return reject(err)
        }

        resolve(output)
      })
    })
  })
  .then((records) => {
    // process data using parsed records...
    records.forEach(record => {
      console.log(record) /* outputs:
      { 
        loyaltyProgramID: '1',
        loyaltySubledger: '',
        profileIntegrationID: 'customer_1',
        currentBalance: '34.89',
        pendingBalance: '42.1',
        expiredBalance: '0',
        spentBalance: '10'
      }
      */
    })
  })
  .catch(err => console.log(`Error while exporting and processing csv:\n${JSON.stringify(err, null, 2)}`))

☝️ Back to Table of Contents

Expose destroySession Endpoint

Expose an existing endpoint to allow destroying a bearer token used in the context of the management-api.
This endpoint imitates a "logout" function and will make the attached token invalid for consequent requests.

☝️ Back to Table of Contents

Introduce loyalty effects related and referrals creation counters on Campaign entities

As part of the newly added budgets to campaigns (see relevant Help Center Section), we have added new counters on campaigns with regard to loyalty and referrals:

  • createdLoyaltyPointsCount : Total number of loyalty points created by rules in this campaign
  • createdLoyaltyPointsEffectCount : Total number of loyalty point creation effects triggered by rules in this campaign
  • redeemedLoyaltyPointsCount : Total number of loyalty points redeemed by rules in this campaign
  • redeemedLoyaltyPointsEffectCount : Total number of loyalty point redemption effects triggered by rules in this campaign
  • referralCreationCount : Total number of referrals created by rules in this campaign

☝️ Back to Table of Contents

Integration API

Improve Responses Transparency

We are constantly extending and improving our integration API to provide our consumers with the best transparency regarding what exactly has happened within their requests.

We have added new data points to our v2 endpoints effects in order to improve the transparency we aspire for:

  • If an effect was triggered because of a specific coupon the effect will now include this coupon ID, see Effect.md
  • When a coupon is rejected we attach more details regarding the origin of the failure in RejectCouponEffectProps:
    • ConditionIndex - The index of the condition that caused the rejection of the coupon
    • EffectIndex - The index of the effect that caused the rejection of the coupon
    • Details - More details about the failure (if available)
  • The same applies for referrals, when a referral is rejected we attach more details regarding the origin of the failure in RejectReferralEffectProps:
    • ConditionIndex - The index of the condition that caused the rejection of the referral
    • EffectIndex - The index of the effect that caused the rejection of the referral
    • Details - More details about the failure (if available)

Moreover, we have introduced a new response content, ruleFailureReasons, which when requested will attach to the response a collection containing all failed rules, with details (see the ruleFailureReason model to help narrowing down failures and further debugging efforts to a specific single condition or effect that caused the failure.

One "gotcha" to keep in mind: in order to maximize transparency, and due to the fact that we do not know in advance which campaign in the application the request targets, the list contains a collection of all failure reasons.

Meaning that, it might have "white noise" with data about failures that could be considered as "obvious" to the consumer. Therefore, we suggest always filtering the list by the campaign id that was expected to trigger and did not.

☝️ Back to Table of Contents

Attach Loyalty Program ID in responses

When the consumer requires that the response will contain the details of loyalty programs involved in processing the requests, we now attach the identifier of the loyalty program to the returned loyaltyProgramLedgers models.

The idea behind attaching the identifier is to help streamline further potential requests to our Management API with regard to details about a Loyalty Program, for example getLoyaltyStatistics or getLoyaltyPoints, that require the program identifier as part of the URI of the endpoint.

☝️ Back to Table of Contents

⚠️ A reminder of The Deprecation Notice: Integration API@v1 endpoints

The deprecation was introduced already in the last release of the SDK, here is a kind reminder of the deprecation notices for Integration API@v1 endpoints:

These endpoints will be flagged deprecated on 15.07.2021, meaning support for requests to these endpoints will end on that date. We will not remove the endpoints, and they will still be accessible for you to use.

We highly encourage migrating to the correspondent v2 endpoints for easier and more granular integration, as well as new features support (See our developer docs section about API V2.0).

☝️ Back to Table of Contents

Improve Typescript definitions for optional request parameters

Thanks to @emadgit and their reported issue regarding the topic, we have conducted some ground work to improve the JSDoc definitions the OpenAPI Generator produces.

This allows us to emit optional parameters type definitions correctly and flag them as optional arguments to the different API functions.
However, there is a bug in the current Generator functionality, which doesn't infer types of enum-typed parameters correctly in optional bags, which unfortunately results in not fully correct emitted type definitions for those bags.
For example, one can see that the the campaignState parameter of the getCampaigns request is wrongly inferred as module:model/String instead of simply String or the correct Enum definition.

/**
* List your Campaigns
* @param {Number} applicationId
* @param {Object} opts Optional parameters
* @param {Number} opts.pageSize The number of items to include in this response. When omitted, the maximum value of 1000 will be used.
* @param {Number} opts.skip Skips the given number of items when paging through large result sets.
* @param {String} opts.sort The field by which results should be sorted. Sorting defaults to ascending order, prefix the field name with `-` to sort in descending order.
* @param {module:model/String} opts.campaignState Filter results by the state of the campaign.
* @param {String} opts.name Filter results performing case-insensitive matching against the name of the campaign.
* @param {String} opts.tags Filter results performing case-insensitive matching against the tags of the campaign. When used in conjunction with the \"name\" query parameter, a logical OR will be performed to search both tags and name for the provided values
* @param {Date} opts.createdBefore Filter results comparing the parameter value, expected to be an RFC3339 timestamp string, to the campaign creation timestamp.
* @param {Date} opts.createdAfter Filter results comparing the parameter value, expected to be an RFC3339 timestamp string, to the campaign creation timestamp.
* @param {Number} opts.campaignGroupId Filter results to campaigns owned by the specified campaign group ID.
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/InlineResponse2002}
*/
getCampaigns(applicationId, opts) {

That in turn leads to their emitted typescript definition inference as any, and ignoring the fact that they are optional.

We are investigating the issue and will hopefully be able to open a bug report and suggest a patch to the OpenAPI Generator team.

In the meantime, a workaround could be to type the optional bags as any before passing them to the requests to avoid the TS compiler from complaining:

const managerApi = new TalonOne.ManagementApi();

// no opts provided at all - now valid 🎉 
managerApi.getCampaigns(/* applicationId */ 1)

// untyped opts provided with selective parameters - still fails 😞 due to the above-mentioned issue
managerApi.getCampaigns(/* applicationId */ 1, { tags: 'retargeting'})

// opts typed as `any` - valid  🎉 
const opts: any = {
  tags: 'retargeting'
}

managerApi.getCampaigns(/* applicationId */ 1, opts)

resolves #21

☝️ Back to Table of Contents

Misc: OpenAPI Generator version upgrade

We have upgraded the OpenAPI Generator used to release this SDK from v4.2.3 to v4.3.1 which includes a few subtle improvements in the generated code, for full list of changes, please consult the release logs' under the Javascript section.

☝️ Back to Table of Contents

@altJake altJake self-assigned this Feb 2, 2021
@altJake altJake merged commit bd62e8f into master Feb 3, 2021
@altJake altJake deleted the v4.3.0 branch February 3, 2021 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional opts parameter is not defined as optional
1 participant