Hello,
I've successfully used WebAPI to create a test account using the sample tutorials online, getting a proper "Connection returned HTTP code: 201 with message: Created", however when I go into dynamics to view the newly created account, it is not there.
Account created with:
{
"name ": "TEST ACCOUNT ",
"creditonhold ": false,
"address1_latitude ": 47.639583,
"description ": "This is the description of the sample account ",
"revenue": 5000000,
"accountcategorycode": 1
}
Response:
Connection returned HTTP code: 201 with message: Created and also this {"@odata.context":""@odata.etag":"W/\"5431785\"","name":"TEST">XXX.crm.dynamics.com/.../$metadata ACCOUNT","creditonhold":false,"address1_latitude":47.63958,"description":"This is the description of the sample account","revenue":5000000.0000,"accountcategorycode":1,"createdon":"2021-06-03T15:52:56Z","accountid":"b17834c2-83c4-eb11-bacc-000d3a9d4415","_transactioncurrencyid_value":"98e940e6-f099-eb11-b1ac-000d3a9dfae9"}
The listing in My Active Accounts has zero accounts.
What am I missing?
Thanks
Turns out the assignment was not working not because there was a problem with the request itself, but because I was using an invalid team id. Once I corrected this, the assignment to the team worked. However, I am back at the original problem: not seeing the created accounts on the account view.
I checked the record for team assignment which shows:
{
"@odata.context":"https://myOrg.crm.dynamics.com/api/data/v9.2/$metadata#accounts(name,owningteam(name))/$entity",
"@odata.etag":"W/\"5456549\"",
"name":"UPDATE WORKED LVUPR",
"accountid":"87945325-e4c4-eb11-bacc-000d3a9d4415",
"owningteam":{"@odata.etag":"W/\"1688787\"",
"name":"myOrg",
"teamid":"d9653907-c799-eb11-b1ac-000d3a9dfae9",
"ownerid":"d9653907-c799-eb11-b1ac-000d3a9dfae9"}
}
Thanks for answering my original question. I will pursue this in another post form here on out. The requests themselves have been verified, there is something else going on.
Sorry, I still can't figure out the problem with your code. Try it with Postman.
Any idea why they are not working in a real environment then?
I see no problem in assigning a record using the web api. I just tested this via postman. Also, I recommend testing your requests using Postman, this tool will allow you to generate code easily.
I found this on another post, is it accurate?
"Changing the owner of the record is not an Update operation. This is Assign operation, and unfortunately there is no possibility to assign record using REST request"
String uri = "https://myOrg.crm.dynamics.com/api/data/v8.2/accounts(87945325-e4c4-eb11-bacc-000d3a9d4415)"; URL url = new URL(uri); addHttpPatch(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); String JSON = "{" " \"name\": \"UPDATE WORKED\"," " \"ownerid@odata.bind\": \"/teams(7193eb97-5d04-4d02-aae5-e1b9b4eaab28)\"," " \"owningteam@odata.bind\": \"/teams(7193eb97-5d04-4d02-aae5-e1b9b4eaab28)\"" " }"; conn.setRequestMethod("PATCH"); conn.setRequestProperty("Authorization", "Bearer " accessToken); conn.setRequestProperty("Accept","application/json"); conn.setRequestProperty("OData-MaxVersion","4.0"); conn.setRequestProperty("OData-Version","4.0"); conn.setRequestProperty("Content-Type"," application/json; charset=utf-8"); conn.setRequestProperty("Prefer","return=representation"); conn.setRequestProperty("X-HTTP-Method-Override", "PATCH"); conn.setDoOutput(true); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(JSON); wr.flush(); wr.close(); int httpResponseCode = conn.getResponseCode(); if(httpResponseCode == HttpURLConnection.HTTP_OK) { StringBuilder response; try(BufferedReader in = new BufferedReader( new InputStreamReader(conn.getInputStream()))){ String inputLine; response = new StringBuilder(); while (( inputLine = in.readLine()) != null) { response.append(inputLine); } } return response.toString(); } else { BufferedReader in = null; InputStream input =null; input = conn.getInputStream(); in = new BufferedReader(new InputStreamReader(input)); String returnData = ""; String inputLine; while ((inputLine = in.readLine()) != null) returnData = inputLine "\n"; in.close(); return String.format("Connection returned HTTP code: %s with message: %s and also this %s", httpResponseCode, conn.getResponseMessage(),returnData); }
Please share your Java Code.
One thing I noticed in your last reply was 'ownerid@odata.bind' as opposed to 'ownerid@odata.value' that I was using. When I switch to bind, I get a 'FileNotFoundException'. I assume it is saying the team I am trying to assign does not exist? I did create the team as a ADD Security Group team using the Azure Object ID from Azure.
Thanks,
This is actually a java app, not JavaScript, but to your point I have tried adding the ownerid (and owningteam) assignments during a create and update with the following additions to the JSON object:
{
"name": "TEST ACCOUNT4","
"ownerid@odata.value": "/teams(2a248d2e-c84e-40db-b9d1-934391c6c77b)","
"owningteam@odata.value": "/teams(2a248d2e-c84e-40db-b9d1-934391c6c77b)","
"creditonhold": false,"
"address1_latitude": 47.639583,"
"description": "This is the description of the sample account","
"revenue": 5000000,"
"accountcategorycode": 1,"
"statecode": 1,"
"statuscode": 1"
}
Both return successful responses and all of the other fields are set properly, yet the ownerid/owningteam remains the same:
{"@odata.context":""@odata.etag":"W/\"5443065\"","name":"TEST">myOrg.crm.dynamics.com/.../$metadata ACCOUNT4","accountid":"b57dc17d-edc4-eb11-bacc-000d3a9d4415","owningteam":null}
{"@odata.context":""@odata.etag":"W/\"5443065\"","name":"TEST">myOrg.crm.dynamics.com/.../$metadata ACCOUNT4","accountid":"b57dc17d-edc4-eb11-bacc-000d3a9d4415","owninguser":{"@odata.etag":"W/\"5146454\"","fullname":"myOrg Platform","systemuserid":"e3122b2b-59bf-eb11-8236-000d3a100d4b","ownerid":"e3122b2b-59bf-eb11-8236-000d3a100d4b"}}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,522 Super User 2024 Season 2
Martin Dráb 228,441 Most Valuable Professional
nmaenpaa 101,148