私はJavaアプリケーションを持っており、crm web apiを使用して機会を更新しようとしています。私がパッチのような非標準的なHTTPメソッド(更新のために必要です)を使用して、さまざまなサンプルコードで見つけたように "X-HTTP-Method-Override"で上書きしようとすると、動かない。機会更新のJavaとMS CRM 2016 Web APIアップデート
コード:
{
"error":{
"code":"","message":"Unmapped Request found, PathTemplate:~/entityset/key, HttpVerb:POST","innererror":{
"message":"Unmapped Request found, PathTemplate:~/entityset/key, HttpVerb:POST","type":"Microsoft.Crm.CrmHttpException","stacktrace":" at Microsoft.Crm.Extensibility.OData.EntityController.HandleUnmappedRequest(ODataPath path)\r\n at lambda_method(Closure , Object , Object[])\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
私は試してみました。このエラーのためにウェブ上の任意の情報を見つけることができませんでした後:
public int updateOpportunity(OpportunityDaoModel model) throws IOException, URISyntaxException {
JSONObject opportunity = new JSONObject();
opportunity.put("name", model.getTopic());
HttpURLConnection connection = null;
URL url = new URL(RESOURCE + "/api/data/"+API_VERSION+"/opportunities(" + model.getCrmguid() + ")");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
connection.setRequestProperty("OData-MaxVersion", "4.0");
connection.setRequestProperty("OData-Version", "4.0");
connection.setRequestProperty("Accept", "application/json");
connection.addRequestProperty("Authorization", "Bearer " + token);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
connection.connect();
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(opportunity.toString());
out.flush();
out.close();
int responseCode = connection.getResponseCode();
return responseCode;
}
私は次のエラーを取得するこの方法を実行した後別のエントリを作成し、PUT経由で単一の属性の更新を使用したいと考えました。これは通常の属性(多くのエンティティのname属性など)で成功しますが、ルックアップフィールドを更新しようとすると別のエラーが発生します。しかし、最初に私の方法:
コード単一の属性の更新のために:すべてのいただきありがとうございます
{
"error":{
"code":"","message":"Operation not supported on opportunity","innererror":{
"message":"Operation not supported on opportunity","type":"Microsoft.Crm.CrmHttpException","stacktrace":" at Microsoft.Crm.Extensibility.OData.EntityController.PutEntity(String entityName, String key, EdmEntityObject entity)\r\n at lambda_method(Closure , Object , Object[])\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
:
public int updateAttribute(String entity, String id, String attribute, String value) throws IOException, URISyntaxException {
JSONObject opportunity = new JSONObject();
HttpURLConnection connection = null;
String urlString = "";
if(attribute.contains("@odata.bind")) { // lookup value
urlString = RESOURCE + "/api/data/"+API_VERSION+"/"+entity+"(" + id + ")";
opportunity.put(attribute, value);
} else { // text value
urlString = RESOURCE + "/api/data/"+API_VERSION+"/"+entity+"(" + id + ")/" + attribute;
opportunity.put("value", value);
}
URL url = new URL(urlString);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("PUT");
connection.setRequestProperty("OData-MaxVersion", "4.0");
connection.setRequestProperty("OData-Version", "4.0");
connection.setRequestProperty("Accept", "application/json");
connection.addRequestProperty("Authorization", "Bearer " + token);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
connection.connect();
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(opportunity.toString());
out.flush();
out.close();
int responseCode = connection.getResponseCode();
return responseCode;
}
iは、エラーメッセージ
updateAttribute("opportunities", model.getCrmguid(), "[email protected]", "/entityendpointwiths("+model.getProgress()+")");
を経由してこのメソッドを呼び出します助けて。
敬具、デニス
私は、興味深い記事を見つけました。残念ながら、それは助けにはなりません:https://msdn.microsoft.com/en-us/library/mt607875.aspx#Anchor_3 –