We have MS Dynamics 365 Business Central installed on our server (I'm not sure how to view the currently installed version). For our requests, we use the oData v4 protocol.
Task
This system requires API calls from PHP.
Issue
When a GET request works properly, it is impossible to make POST, PATCH, or DELETE requests.
Get
Request:
GET https://d365bc.vendor.com:7058/attain/ODataV4/Company('{{company}}')/Customer
Response
{
"@odata.context": "https://d365bc.vendor.com:7058/attain/ODataV4/$metadata#Company('...')/Customer",
"value": [
{
"@odata.etag": "W/\"JzQ0O29EcmJmcGs4V3NRMHlEQ0Fxa0JxL1N0bi9xZjY5UDFQakZ0U2tBUGU1Kzg9MTswMDsn\"",
"No": "01121212",
"Name": "Spotsmeyer's Furnishings",
"Responsibility_Center": "",
"Location_Code": "YELLOW",
"Post_Code": "US-FL 37125",
"Country_Region_Code": "US",
"Phone_No": "",
"IC_Partner_Code": "",
"Contact": "Mr. Mike Nash",
"Salesperson_Code": "JR",
"Customer_Posting_Group": "FOREIGN",
"Gen_Bus_Posting_Group": "EXPORT",
"VAT_Bus_Posting_Group": "EXPORT",
"Customer_Price_Group": "",
"Customer_Disc_Group": "",
"Payment_Terms_Code": "1M(8D)",
"Reminder_Terms_Code": "FOREIGN",
"Fin_Charge_Terms_Code": "2.0 FOR.",
"Currency_Code": "USD",
"Language_Code": "ENU",
"Search_Name": "SPOTSMEYER'S FURNISHINGS",
"Credit_Limit_LCY": 0,
"Blocked": " ",
"Privacy_Blocked": false,
"Last_Date_Modified": "2020-06-18",
"Application_Method": "Manual",
"Combine_Shipments": true,
"Reserve": "Optional",
"Shipping_Advice": "Partial",
"Shipping_Agent_Code": "",
"Base_Calendar_Code": "",
"Balance_LCY": 0,
"Balance_Due_LCY": 0,
"Sales_LCY": 0,
"Global_Dimension_1_Filter": "",
"Global_Dimension_2_Filter": "",
"Currency_Filter": "",
"Date_Filter": "..11/13/20"
},
{
"@odata.etag": "W/\"JzQ0O08vNlVHSWVaZ1FGeG42d2JOa3k4Qm5uVHlkSGYzNk1ES2V5Y2E2S3hiekU9MTswMDsn\"",
"No": "01445544",
"Name": "Progressive Home Furnishings",
"Responsibility_Center": "",
"Location_Code": "YELLOW",
"Post_Code": "US-IL 61236",
"Country_Region_Code": "US",
"Phone_No": "",
"IC_Partner_Code": "",
"Contact": "Mr. Scott Mitchell",
"Salesperson_Code": "JR",
"Customer_Posting_Group": "FOREIGN",
"Gen_Bus_Posting_Group": "EXPORT",
"VAT_Bus_Posting_Group": "EXPORT",
"Customer_Price_Group": "",
"Customer_Disc_Group": "RETAIL",
"Payment_Terms_Code": "14 DAYS",
"Reminder_Terms_Code": "FOREIGN",
"Fin_Charge_Terms_Code": "2.0 FOR.",
"Currency_Code": "USD",
"Language_Code": "ENU",
"Search_Name": "PROGRESSIVE HOME FURNISHINGS",
"Credit_Limit_LCY": 0,
"Blocked": " ",
"Privacy_Blocked": false,
"Last_Date_Modified": "2018-09-19",
"Application_Method": "Manual",
"Combine_Shipments": true,
"Reserve": "Optional",
"Shipping_Advice": "Partial",
"Shipping_Agent_Code": "",
"Base_Calendar_Code": "",
"Balance_LCY": 1499.03,
"Balance_Due_LCY": 1499.03,
"Sales_LCY": 1499.03,
"Global_Dimension_1_Filter": "",
"Global_Dimension_2_Filter": "",
"Currency_Filter": "",
"Date_Filter": "..11/13/20"
},
DELETE
DELETE https://d365bc.vendor.com:7058/attain/ODataV4/Company('{{company}}')/Customer(No='01121212')
{
"error": {
"code": "BadRequest",
"message": "Entity does not support delete."
}
}
I am unsure of the proper syntax for Create (POST) or Update (Patch) I attempted to copy an existing value from the GET request and insert it into the POST request's body. I'm getting following response:
{
"error": {
"code": "BadRequest_MethodNotAllowed",
"message": "Entity does not support insert."
}
}
Sometimes, if I make a completely incorrect request, I receive the following response:
{
"error": {
"code": "BadRequest_MethodNotAllowed",
"message": "'POST' requests for 'Customer' of EdmType 'Entity' are not allowed within Microsoft Dynamics 365 Business Central OData web services."
}
}
Customers and ProductItems CUD operations cannot be applied. However, it's effective for orders.
Existing Privileges
If I follow
Setup & Extensions / Manual Setup / Users / [Select User]
In the permissions section, too many privileges are assigned. There is a SUPER privileges item among them. As far as I am aware, all names there are unique. Here is a screenshot of the granted permissions.
UPD 1.
I tried to follow this guide: https://learn.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/
I have on-prem installation and for me it's not clear what is the correct endpoint for any operation.
For example, I can make following request:
https://d365bc.vendor.com:7057/attain/WS/CRONUS%20International%20Ltd/Page/Customer
As a result, I am receiving a scheme, but neither customers nor the ability to perform any actions with them.
As far as I can tell, this guide only contains cloud installation.
Extension APIs:
https://<base URL>:<port>/<serverinstance>/api/<API publisher>/<API group>/<API version>
Am I doing everything correct? What do these params mean? No explanation provided in the guide.
Upd.2
Regarding requirements:
API must be enabled on the Business Central server instance:
So port is 7057, API URL is https://d365bc.vendor.com:7057/Attain/WS/
What is WS, is it really required? By the URL above I'm getting this:
The user used for authentication must have a Web Service Access Key (created for the user in Business Central)
There was nothing in this section, I've added new key. And now it looks like this. But it didn't change anything in my case. Still same errors: 405 for the port 7057 and 404 for the port 7058.
p.s. Is it enough to simply generate it? Or we need to use it somewhere?
The user must have the required permissions within Business Central for the relevant API's.
Is it managing at the following page?
Here are responses examples:
Url was changed after execution with the correct Vendor name in the domain name.
Here's a link that may help you.
OData Web Services Data Modification - Business Central | Microsoft Learn