如何使用Odata Dynamics NAV 2017 Web服务删除记录 [英] How to Delete records using Odata Dynamics NAV 2017 web services

查看:363
本文介绍了如何使用Odata Dynamics NAV 2017 Web服务删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个可连接到Microsoft Dynamics导航2017 OData Web服务的php应用程序,我可以毫无问题地读取(GET)和创建(POST),但是对于删除,我收到错误405,微软说这是可以删除:

I was developed a php application that connects to Microsoft Dynamics NAV 2017 OData Web Services, I can read (GET), and create (POST) with no problems,but for delete I receive the error 405, Microsoft say that it is possible to delete :

https://msdn.microsoft. com/es-es/library/dd355398(v = nav.90).aspx

https://msdn.microsoft. com/en-us/library/dn182582(v = nav.90).aspx

我检查Dynamics NAV中具有正确属性InsertAllowed,ModifyAllowed或DeleteAllowed的页面,将其设置为是",并且我有权删除

I check the page in Dynamics NAV that have a correct property InsertAllowed, ModifyAllowed, or DeleteAllowed, is set to Yes, and I have permissions to delete

尝试邮递员收信后出现相同错误:

After try with postman recevie the same error:

有人可以帮助我吗?谢谢

Can someone help me? Thanks

推荐答案

最后我找到了解决方案! ,我写信来帮助另一个遇到相同问题的人:

Finally I found the solution!! , I write myself to help another who is with the same problem:

您只需在请求url上添加标识符,在我的情况下,就是客户表的标识符('/Customer(No ='.$ identifier.')')

You only have to add the identifier on the request url, in my case the identifier of the customer table ('/Customer(No='.$identifier.')')

这是PHP中的示例代码,带有Dynamics NAV的客户和表客户:

This is a sample code in PHP with guzzle and table customer of Dynamics NAV:

 $client = new GuzzleHttpClient();
 $uri=env('HTTP_URIBASE', '');
 $apiRequest = $client->request('DELETE', $uri.'/Customer(No='.$identifier.')',[
        'auth' => [env('HTTP_USERNAME', 'usuari'),env('HTTP_PASSWORD', ''), 'ntlm' ],
        'headers' => ['Content-Type' => 'application/json', 
                       'Accept' => 'application/json']
  ]);
  $content = json_decode($apiRequest->getBody()->getContents());

有关更新( PATCH ),我必须先阅读记录( @ odata.etag )的 etag ,然后在标头(如果匹配值)进行更新:

for updates (PATCH) I have to first read the etag of the reccord (@odata.etag), and add on the headers (If-Match value) for update:

 $client = new GuzzleHttpClient();
 $uri=env('HTTP_URIBASE', '');
 // get the recordset of the customer
 $apiRequest = $client->request('GET', $uri.'/Customer(No='.$identifier.')',[
            'auth' => [env('HTTP_USERNAME', 'usuari'),env('HTTP_PASSWORD', ''), 'ntlm' ]     
            ]);
 $content = json_decode($apiRequest->getBody()->getContents());
 $etag= $content->{'@odata.etag'};

 // update description of the customer
 $apiRequest = $client->request('PATCH', $uri.'/Customer(No='.$identifier.')',[
        'auth' => [env('HTTP_USERNAME', 'usuari'),env('HTTP_PASSWORD', ''), 'ntlm' ],
        'headers' => ['Content-Type' => 'application/json', 
                       'Accept' => 'application/json',
                       'If-Match' =>$etag ],
        'body'    => '{"Name":"'.$missatge.'"}' 
         ]);
 $content = json_decode($apiRequest->getBody()->getContents());

这篇关于如何使用Odata Dynamics NAV 2017 Web服务删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆