Skip to main content

Notifications

Announcements

No record found.

Supply chain | Supply Chain Management, Commerce
Unanswered

OData/WebAPI DELETE for Product Category is returning 204 but the entity is not actually being deleting

(0) ShareShare
ReportReport
Posted on by 15

I'm going crazy and can't figure this out. 

In Postman, I'm calling 

  • GET {{d365BaseUrl}}/data/ProductCategories(ProductCategoryHierarchyName='Physical Inventory',CategoryName='test4') -- This works just fine and returns the prodcut category
  • DELETE {{d365BaseUrl}}/data/ProductCategories(ProductCategoryHierarchyName='Physical Inventory',CategoryName='test4') -- Returns a 204 and I assume it's deleted
  • NOPE It's still there!  I've tried passing an empty body {} as I saw in a related post for CRM, but that didn't help at all.  This is D365 F&O / Supply Chain Management.

Deleting items with Postman works just fine for ProductsV2, but not for Product Categories.  I'm baffled.  

Any help would be greatly appreciated.

Thanks,
Tom

  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    RE: OData/WebAPI DELETE for Product Category is returning 204 but the entity is not actually being deleting

    Then I would debug the entity to see where things go wrong.

  • tomhundley Profile Picture
    tomhundley 15 on at
    RE: OData/WebAPI DELETE for Product Category is returning 204 but the entity is not actually being deleting

    Really?  Yes, it's tested.  It's not an assumption.  The Product Categories can be deleted from the UI without issue.  

    The UI actually uses https://...Services/ReliableCommunicationManager.svc/ProcessMessages?cmp=abc&lng=en-us& instead of making a restful call, which I was hoping to see.  

    For whatever it's worth, the UI does prompt and ask if the user wants to check if the category is referenced by other documents.  I'm wondering if that has anything to do with it, perhaps there is another method/resource that needs to be called or pass something in the body stating that the delete operation is "confirmed", however, the documentation that I can find doesn't say anything of the sort.  And again, using both Postman and an OData client in c# return success statueses from the server, although it's not deleted.

  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    RE: OData/WebAPI DELETE for Product Category is returning 204 but the entity is not actually being deleting

    Can you please test your assumption that it should be able to get deleted?

  • tomhundley Profile Picture
    tomhundley 15 on at
    RE: OData/WebAPI DELETE for Product Category is returning 204 but the entity is not actually being deleting

    Yes it should be able to be deleted; there is nothing assigned to them.  And if that were the case, I'd hope for an HTTP status code other than success or no content/204.  Thanks for the thought though!

  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    RE: OData/WebAPI DELETE for Product Category is returning 204 but the entity is not actually being deleting

    Can the category be deleted? Maybe it can't, because it's already used somewhere and deleting it would lead to inconsistent database.

  • tomhundley Profile Picture
    tomhundley 15 on at
    RE: OData/WebAPI DELETE for Product Category is returning 204 but the entity is not actually being deleting

    Update: Not that I really expected anything different, but using the Odata client in c# performs the exact same way.  I call delete and the data is still there:

        class Program
        {
            public static string ODataEntityPath = ClientConfiguration.Default.ActiveDirectoryResource   "/data";
            static void Main(string[] args)
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute);
                var context = new Resources(oDataUri);
    
                context.SendingRequest2  = new EventHandler(delegate (object sender, SendingRequest2EventArgs e)
                    {
                        var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true);
                        e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);
                    });
    
    
                var category = context.ProductCategories.AsEnumerable().SingleOrDefault(p => p.ProductCategoryHierarchyName == "Physical Inventory" && p.CategoryName == "test4");
                if (category == null)
                {
                    Console.WriteLine("can't find category");
                    Console.ReadLine();
                    return;
    
                }
    
                context.DeleteObject(category);
                context.SaveChanges();
    
                Console.ReadLine();
            }
        }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans