cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
saumiltrivedi14
New Member

Operation return invalid status code 'Bad Request' : Microsoft.Powerplatform.Cds.Client -Version 0.2.14-Alpha

Our Requirement:
We have Azure Linux server resource group. So we need to create azure function in .net core 3.1.

So, we got the following package which provide supports in .net core azure function
Microsoft.Powerplatform.Cds.Client -Version 0.2.14-Alpha

 

Let me include few details about our implementation:

1. We have used Dynamics connection string - ClientSecret Authentication types

2. Following things working fine with the above connection string.

 - Retrieve records from Entities - Working fine.

 - Insert/Update operation in Entity which doesn't contain EntityReference type (Lookup) - Working fine.

3. When we perform Insert/update operation in Entity which contains EntityReference type (Lookup), it gives error
Operation return invalid status code 'Bad Request'

 

Let me attach some code which we implemented in console application:

 

var service = new CdsServiceClient(connectionString);
 if (service.IsReady)
 {
   Entity account = GetAccountEntity(service);
   Entity coupon = GetCouponEntity(service);


   Entity couponPerCustomer = new Entity("couponpercustomer");
   couponPerCustomer["couponid"] = coupon.ToEntityReference();
   couponPerCustomer["customerid"] = account.ToEntityReference();
   service.Create(couponPerCustomer);
 }

 

When we run above code it gives error in "service.Create(couponPerCustomer)"
Error: Operation return invalid status code 'Bad Request'

5 REPLIES 5
ben-thompson
Solution Sage
Solution Sage

You can't just convert an entity to an entity reference as an entity contains far more data.

 

An entityreference consists of 2 parts the logicalname of the entity you are referencing and the id of the entity. Thankfully getting the id from the entity is easy so you can use either of 

 

couponPerCustomer["couponid"] = new EntityReference("coupon",coupon.Id);
   couponPerCustomer["customerid"] = new EntityReference("account",account.Id);

 

or

 

couponPerCustomer["couponid"] = new EntityReference(coupon.LogicalName,coupon.Id);
   couponPerCustomer["customerid"] = new EntityReference(account.LogicalName,account.Id);

 

both of which will give you valid entityreferences.

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".

Hi ben-thompson,
Thanks for the quick reply.


We have already tried this solution
    couponPerCustomer["couponid"] = new EntityReference(coupon.LogicalName,coupon.Id);
   couponPerCustomer["customerid"] = new EntityReference(account.LogicalName,account.Id);

It is not working for us.


DianaBirkelbach
Super User
Super User

Hi @saumiltrivedi14 ,

I wonder if "couponpercustomer" is a N:N relationship. That would mean that you would need an "associate" request, instead of create.

Maybe you get more details in the error call stack?

 

Kind regards,

Diana

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Hi @DianaBirkelbach 
We have 1:N relationship.
Same code is working fine with package Microsoft.CrmSdk.XrmTooling.CoreAssembly inside .net Framework Project.
But above package has dependency of .net Framework.
As per new requirement, we have to use .net core project.
So, we are using .net core compatible package: Microsoft.Powerplatform.Cds.Client -Version 0.2.14-Alpha

 

We are getting error Operation return invalid status code 'Bad Request'

 

As I posted in your other thread - the .net core packages are alpha code and support is being done via the github repository at

 

https://github.com/microsoft/PowerPlatform-CdsServiceClient/issues

 

But I'm not sure I would be using alpha code to fulfil any requirement and I would be pushing back and saying the only option is to use the .net framework which is both supported (and no importantly for your requirement actually works)

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,573)