Webservice, OData, PHP modify example?

Ramonchu
Member Posts: 31
Hello.
I'm creating a tool in PHP as a REST interface, with Curl. For testing I've created a webservice for Customer card page. I can read without problems, but when I try to PUT to modify the card of a customer, I get this error:
"Could not validate the client concurrency token required by the service. Please provide a valid token in the client request."
Reading the forum I've seen that I have to read an ID and use that ID to PUT, so NAV can check there are not modifications between operations, but there is no information about how to do it.
Do you have an example about how to modify using PHP and ODATA? I don't know if the problem comes from that ID, from a token, authentication....
Thanks!
I'm creating a tool in PHP as a REST interface, with Curl. For testing I've created a webservice for Customer card page. I can read without problems, but when I try to PUT to modify the card of a customer, I get this error:
"Could not validate the client concurrency token required by the service. Please provide a valid token in the client request."
Reading the forum I've seen that I have to read an ID and use that ID to PUT, so NAV can check there are not modifications between operations, but there is no information about how to do it.
Do you have an example about how to modify using PHP and ODATA? I don't know if the problem comes from that ID, from a token, authentication....
Thanks!
0
Answers
-
When you read a record, there is an additional column added called Bookmark if I remember correctly, which is the information NAV needs to deal with concurrent users. When you change a value and modify the record, that Bookmark is still there and you should not have any problems with that. So make sure you have this information, it's a very long string, and this information is still present when you try to modify it. I do not have my PHP close at hand, but I could look for some examples at a later time.0
-
On a second thought, you're using REST. Actually I think that might be your problem. Because this token is one of the params and probably is way too long to be included in a REST request. I never tried that and I probably never will because to me it seems as an odd way of doing things. I think you should use a PHP SOAP client.0
-
Hello Marijn. Thanks for your help.
The only field that i see is this:
ETag: 28;EgAAAAJ7BTAAMAAwADAAMQAAAAAA8;257624890;
I think that should be the field, so if I send a PUT, do I have to include that tag along with the fields to modify? or where do I have to include that field?
Example:
$ch = curl_init();
$customer = '00001';
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Connection: Keep-Alive',
'Accept: application/json',
'Content-Type: application/json; charset=utf-8',
"Accept: */*"
]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERPWD, *myuserandpassword*);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'Phone_No' => '123456789',
'ETag' => "28;EgAAAAJ7BTAAMAAwADAAMQAAAAAA8;257624890"
]));
$api_request_url = "http://192.168.1.19:7048/DynamicsNAV90/OData/Company('TEST')/Customer('$customer')";
curl_setopt($ch, CURLOPT_URL, $api_request_url);
$response = json_decode(curl_exec($ch), TRUE);
With that code I get the error.
Best regards.0 -
Yes, you need to include that field, just like it was part of a primary key. I don't remember the name being ETag. In NAV2009 the token was named Bookmark if I am not mistaken. But I am not sure whether curl is the right tool for the job. If you can read a record, I suppose it can be done. You should be able to read a record. And without any changes, save it right away.0
-
Maybe you should put ETag at the top as the very first parameter.0
-
I've tried both things, in key (where I get a key error) and as first paramenter, but both don't work. I have no example where to put that tag.... no idea.0
-
Then I can't help you. I only got experience with PHP calling the NAV webservices with SOAP, not ODATA and REST. I used Freddys Blog as a starting point: https://blogs.msdn.microsoft.com/freddyk/2010/01/19/connecting-to-nav-web-services-from-php/
Not sure whether that helps you.0 -
Please use fallowing example for PHP consuming NAV webservices
https://onedrive.live.com/redir?resid=2D58FE62FC930D3B!933&authkey=!AFmzxXzJGCbCCEc&ithint=folder,zip
Hope this Helps
Thanks
www.moulikaku.comHope this Helps
Thanks
Mouli K
www.moulikaku.com0 -
Hello.
Thank you for your answers. I already had that zip file for Soap.
Finally I solved the problem with the kind help of John Slegers (for Odata).
With Soap I have a php error but I've read I have to activate NTLM authentication in the nav service. I have to test...
With OData, the ETag is the field that must be read and used to modify or delete. That field must be sent in the header of the "Patch" call (with curl). There is also a curl parameter to include if you use http or https call (for authentication). I will test in deep everything and post the results.
Thank you for your help!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions