Skip to main content
Solved

REST API Sales Order discount details: 'Type' cannot be empty

  • December 31, 2024
  • 6 replies
  • 209 views

Forum|alt.badge.img

Hello,

 

I’m attempting to create a Sales Order via the REST API and I’m running into an error I don’t understand when applying a discount.

 

My DiscountDetails JSON payload looks like this:

 

  "DiscountDetails": [
        {
            "Description": {
                "value": "Coupon Discount"
            },
            "DiscountCode": {
                "value": "COUPON"
            },
            "DiscountPercent": {
                "value": 15
            },
            "DiscountAmount": {
                "value": 0.6
            },
            "ManualDiscount": {
              "value": true
            },
            "SequenceID": {
              "value": "TATER15"
            },
            "Type": {
                "value": "Document"
            }
        }
  ]

The error I’m receiving is “’Type’ cannot be empty”, but I am providing a “Type”, so I don’t really understand what’s wrong. There are no other errors.

 

The error only seems to occur when using the REST API; I have been able to successfully apply the same discount to a Sales Order using the Acumatica UI.

 

Any ideas? Thanks!

 

Best answer by dominicfedco

Thank you, I was able to successfully add the discount by either 1. sending a second API request to update the sales order after creation (the error only occurred on initial creation) or 2. changing the sales order’s OrderType (maybe this points to an issue w/ the way this type was configured?)

 

I still don’t understand the root cause, but this issue has been resolved for me. I appreciate the quick assistance!

6 replies

darylbowman
Captain II
Forum|alt.badge.img+15
  • December 31, 2024

The ‘Type’ option keys are:

Line = "L"
Group = "G"
Document = "D"
ExternalDocument = "B"
Flat = "F"

Have you tried “D” instead of “Document”?


Forum|alt.badge.img
  • Author
  • Freshman II
  • December 31, 2024

Thanks for the reply, Daryl! I’m curious where this list is located, I didn’t see it in the documentation.

 

Sadly, sending “D” rather than “Document” did not resolve the issue. The API still complains about the type field.

 

Here’s the relevant excerpt from the response:

  "DiscountDetails": [
    {
      "id": "e61ac7d6-6778-4f02-aadc-b0655defb1fe",
      "rowNumber": 1,
      "note": null,
      "Description": {
        "value": "Coupon Discount"
      },
      "DiscountableAmount": {},
      "DiscountableQty": {},
      "DiscountAmount": {
        "value": 0.6
      },
      "DiscountCode": {
        "value": "COUPON"
      },
      "DiscountPercent": {
        "value": 0
      },
      "ExternalDiscountCode": {},
      "FreeItem": {},
      "FreeItemQty": {},
      "ManualDiscount": {
        "value": true
      },
      "SequenceID": {
        "value": "TATER15"
      },
      "SkipDiscount": {
        "value": false
      },
      "Type": {
        "error": "'Type' cannot be empty."
      },
      "custom": {}
    }
  ],

 

May be a red herring, but it’s curious to me that the response says DiscountPercent = 0, as opposed to the 15 which I sent to the API endpoint.


darylbowman
Captain II
Forum|alt.badge.img+15
  • December 31, 2024

I believe it is a red herring. Type is not even editable from the UI.

I am able to add a discount to an existing SO with this (however, the DiscountAmount is not being respected for me either, but it’s a step closer):

Host: entity/Default/23.200.001/SalesOrder?$expand=DiscountDetails&$select=OrderType,OrderNbr,DiscountDetails/DiscountCode,DiscountDetails/SequenceID,DiscountDetails/DiscountAmount

{
"OrderType": {
"value": "SO"
},
"OrderNbr": {
"value": "SO007748"
},
"DiscountDetails": [
{
"DiscountCode": { "value": "DOC00C000" },
"SequenceID": { "value": "USBAR" },
"DiscountAmount": { "value": 10.6 }
}
]
}

 


Forum|alt.badge.img
  • Author
  • Freshman II
  • Answer
  • January 6, 2025

Thank you, I was able to successfully add the discount by either 1. sending a second API request to update the sales order after creation (the error only occurred on initial creation) or 2. changing the sales order’s OrderType (maybe this points to an issue w/ the way this type was configured?)

 

I still don’t understand the root cause, but this issue has been resolved for me. I appreciate the quick assistance!


benb1977
Jr Varsity II
Forum|alt.badge.img
  • Jr Varsity II
  • January 8, 2025

Hi all,

I have been working on a similar problem on and off for months and came across this post in searching for an answer. I too was able to get the discount entered but couldn’t get the API to pay attention to the discount percentage or discount amount I was sending. ​@dominicfedco - I can see that you were able to get the discount entered by using a second request, but my client - for whatever reason - needed it all done within one request.

Today I am ecstatic to say that I have finally found the answer. Despite the fact that the ‘Type’ field is not editable through the UI, setting this field to ‘External Document’ and removing the ‘DiscountCode’ and ‘SequenceID’ fields from the message payload allows the discount percentage or discount amount to be set to the value specified in the message payload. I guess this must tell Acumatica that the discount is being set by an external application and that it should not pay any attention to discounts already configured in the application.

I hope this helps anyone else that stumbles across this post looking for the same answers that I was!

Cheers all,

Ben.


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • January 9, 2025

Thank you for sharing your solution with the community ​@benb1977!