Issues when updating products via API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • novastream
    Member
    • May 2021
    • 61

    Issues when updating products via API

    Hi,

    So I've created a parser in C# that gets prices, stock on hand and other info from one of our distributors.

    The products are created manually in EspoCRM then mapped via ID in my parser.

    The problem I'm facing is that if I don't set Cost price field to 0 I get an validation error.

    Endpoint


    Payload
    {
    "url": "https://domain.com/p/powerwalker-vi-2200-lcd-ups-1200watt-2200va-988850910",
    "costPrice": 150.35,
    "weight": 12.16,
    "status": "Available",
    "cStockOnHand": 2,
    "cEanCode": "4260074976502"
    }

    Error
    {
    "messageTranslation": {
    "label": "validationFailure",
    "scope": null,
    "data": {
    "field": "costPrice",
    "type": "validCurrency"
    }
    }
    }

    Now I know how to work around it by setting the initial price to zero. Just wondering if it's the intended behaviour.
  • yuri
    Member
    • Mar 2014
    • 8444

    #2
    Not sure. "validCurrency" validation is failed when a passed currency is not one of the currencies allowed in the system.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • Kharg
      Senior Member
      • Jun 2021
      • 410

      #3
      novastream I had the same "issue", ended up skipping validation for currency fields.

      Sometimes, for whatever reason, it is preferred to bypass Espo's built in field validation rules to avoid triggering the "Field Validation Error" message and interrupting the back end program flow. Fortunately, this is now possible using metadata settings, so it is not necessary to do any coding to accomplish this.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8444

        #4
        I missed your provided payload. Try passing "costPriceCurrency": "USD" in your payload. Use the currency you need instead of USD.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • novastream
          Member
          • May 2021
          • 61

          #5
          Thanks!

          I created a workflow that added costPrice 0 if costPrice was empty on creation but sending costPriceCurrency is working and the correct solution. Thanks both of you.

          Comment

          Working...