Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

WebAPI Create successful, but new account not appearing.

(0) ShareShare
ReportReport
Posted on by 25

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

  • JDCv2.0 Profile Picture
    JDCv2.0 25 on at
    RE: WebAPI Create successful, but new account not appearing.

    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"}
    }
  • JDCv2.0 Profile Picture
    JDCv2.0 25 on at
    RE: WebAPI Create successful, but new account not appearing.

    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.

  • meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: WebAPI Create successful, but new account not appearing.

    Sorry, I still can't figure out the problem with your code. Try it with Postman.

  • JDCv2.0 Profile Picture
    JDCv2.0 25 on at
    RE: WebAPI Create successful, but new account not appearing.

    Any idea why they are not working in a real environment then?

  • meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: WebAPI Create successful, but new account not appearing.

    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.

  • JDCv2.0 Profile Picture
    JDCv2.0 25 on at
    RE: WebAPI Create successful, but new account not appearing.

    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"

  • JDCv2.0 Profile Picture
    JDCv2.0 25 on at
    RE: WebAPI Create successful, but new account not appearing.

    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);
    	        }

  • meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: WebAPI Create successful, but new account not appearing.

    Please share your Java Code.

  • JDCv2.0 Profile Picture
    JDCv2.0 25 on at
    RE: WebAPI Create successful, but new account not appearing.

    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. 

  • JDCv2.0 Profile Picture
    JDCv2.0 25 on at
    RE: WebAPI Create successful, but new account not appearing.

    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"}}

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans