如何使用 Odata Dynamics NAV 2017 Web 服务删除记录

How to Delete records using Odata Dynamics NAV 2017 web services

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

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 设置为是,我有权删除

尝试邮递员后收到同样的错误:

有人可以帮助我吗?谢谢

终于找到解决办法了!! ,我写自己来帮助另一个有同样问题的人:

您只需在请求中添加标识符 url,在我的例子中是客户的标识符 table ('/Customer(No='.$identifier .')')

这是 PHP 中 guzzle 和 table 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) 我必须先阅读记录的 etag (@odata.etag),并添加 headers(If-Match 值)进行更新:

 $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());