Hi,
I am creating a .NET API when i encounter the error and in exception console I see the following:
CODE:
[HttpPost]
[Route("Create")]
public IHttpActionResult CreateInvoice([FromBody] PayablesInvoiceModel invoiceModel)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
try
{
DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
// Create a context with which to call the web service
Context context = new Context();
// Specify which company
CompanyKey companyKey = new CompanyKey();
companyKey.Id = (-1);
// Set up the context
context.OrganizationKey = companyKey;
PayablesInvoice payinv = new PayablesInvoice();
PayablesDocumentKey payInvKey = new PayablesDocumentKey();
payinv.Key = payInvKey;
payinv.BatchKey = invoiceModel.batchId;
payinv.Description = invoiceModel.description;
payinv.VendorDocumentNumber = invoiceModel.vendorDocumentNumber;
payinv.PONumber = invoiceModel.PONumber;
payinv.PurchasesAmount = invoiceModel.PurchasesAmount;
payinv.VendorKey = invoiceModel.VendorId;
payinv.MiscellaneousAmount = invoiceModel.MiscellaneousAmount;
payinv.FreightAmount = invoiceModel.FreightAmount;
Policy payablesInvoicePolicy;
payablesInvoicePolicy = wsDynamicsGP.GetPolicyByOperation("CreatePayablesInvoice", context);
// Create the Invoice
wsDynamicsGP.CreatePayablesInvoice(payinv, context, payablesInvoicePolicy );
wsDynamicsGP.Close();
return Created(new Uri(Request.RequestUri + "/"), invoiceModel);
}
catch (Exception ex)
{
// Log exception details here as needed
return InternalServerError(ex); // Return 500 error code
}
}