终于我找到了解决方案! ,我自己写是为了帮助其他有同样问题的人:
您只需在请求 URL 上添加标识符,在我的例子中是客户表的标识符 ('/客户(No='.$identifier.')')
这是 PHP 中的示例代码,带有 Dynamics NAV 的 guzzle 和表客户:
$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),并添加标题(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());