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!
0
Answers
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.
Not sure whether that helps you.
https://onedrive.live.com/redir?resid=2D58FE62FC930D3B!933&authkey=!AFmzxXzJGCbCCEc&ithint=folder,zip
Hope this Helps
Thanks
www.moulikaku.com
Thanks
Mouli K
www.moulikaku.com
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!