Question

I'm trying to create a new OpportunityProduct using this rest call:

XRMServices/2011/OrganizationData.svc/OpportunityProductSet

{"ProductId":"ef71ce8e-1ef3-e211-b252-984be17c47e4","Quantity":123,"ProductDescription":"Added from code - TEST123","OpportunityId":"8bdb3525-7274-e311-a90b-6c3be5be5f78"}

The call returns:

The request should be a valid top-level resource object.

This indicates that my arguments is not correct. I see to possible reasons for this:

  1. I'm missing some required properties (How can I figure out which is required?)
  2. It is not possible to do using rest

(both guids are returned via other call and should be correct)

Any help would be great!

Thanks

Larsi

Was it helpful?

Solution

For lookup references to other entities you need to specify both the GUID and the type. You also need to include the UOM when creating an Opportunity Product based on an existing Product. Your object should look something like this:

var entity = {};
entity.Quantity = parseFloat(4).toFixed(2);
entity.OpportunityId = {
    Id: '69BB2236-B57F-E311-BB6D-6C3BE5A881A4',
    LogicalName: 'opportunity'
};
entity.ProductId = {
    Id: 'C8138483-DF81-E311-B542-6C3BE5A8362C',
    LogicalName: 'product'
};
entity.UoMId = {
    Id: 'BE0FB859-7E90-4B3E-B501-3AB3CD4DC8FC',
    LogicalName: 'uom'
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top