adzerk / adzerk-management-sdk-js

JavaScript SDK for the Kevel Management API
Apache License 2.0
1 stars 2 forks source link

Simonramzi/sc-57121/updating-caps-via-javascript-sdk-gives-error #93

Closed honeycomb-cheesecake closed 6 months ago

honeycomb-cheesecake commented 7 months ago

Fix for flight decimal values not being set properly via the sdk.

Testing steps:

I used the following script to help after checking out the repo and running npm install && npm run build:

let { buildFullSpecificationList, buildClient, fetchSpecifications } = require("./lib");

async function go() {
  let specificationList = buildFullSpecificationList({
    version: "v1.0.13",
  });

  let specifications = await fetchSpecifications(specificationList);

  let client = await buildClient({
    apiKey: "redacted",
    host: "api-proxy-default.da1.dev.opzerk.com",
    port: 443,
    protocol: "https",
    specifications
  });

  let result = client.run('flight', 'update', {
    id: 1003551986,
    capType: 1,
    dailyCapAmount: 20,
    lifetimeCapAmount: 50,
  });
}

go();
shortcut-integration[bot] commented 7 months ago

This pull request has been linked to Shortcut Story #57121: 🐞 updating caps via Javascript SDK gives error that decimal version doesn't match🐞.

honeycomb-cheesecake commented 7 months ago

@akiradev, your comment on using Math.ceil(capAmountDecimal). Without this we get the following error from the API as the shape requires it to be an integer. The Math.ceil(...) function also complies with DailyCapAmount must be equal to DailyCapAmountDecimal rounded up. requirement (error message that is returned if you set dailyCapAmount to 43 and dailyCapAmountDecimal to 43.12.

{
  "status": 400,
  "body": {
    "Errors": [
      {
        "path": ["body", "DailyCapAmount"],
        "value": 43.12,
        "message": "Value '43.12' at '[:body \"DailyCapAmount\"]' must be an integer, or it may be null."
      }
    ]
  }
}