Find out the metadata (data structure formatted in JSON) of the Web Service you just created. What I did is creating a temporary Console Application and adding the service reference. Then I could check the data type of the sales invoice in Visual Studio.
Decide and map the related fields. Create your own class with the same fields in the Plugin code (the class name can be any, but the type and name of those fields you need to map should be exactly the same as what is in the service reference).
Use DataContractJsonSerializer to serialize your created class for sending it to the web service.
Create a web request to the URL of the Web Service using HttpClient class (username is your account user name in Financials and the password is your web service key).
Send the request to the Web Service using POST method.
Then you maybe want to send the Sales Invoice line items. You should repeat Steps 2 to 6 for the line items: creating a line item class, mapping the fields, serializing it and posting it. The only tricky point is the line item URL is based on the header you previously sent. It looks like:https://yourcompanyname.financials.dynamics.com:7048/MS/ODataV4/..
What’s more tricky is that sometimes the header passed into Financials successfully but the line or lines do not. Then you have to log into Financials and delete the header manually.
To learn more about Microsoft Dynamics 365 for Financials, contact us at [email protected].