web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Verified answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi,

    Maybe the created record is owned by another user or team for some reason...

    Please perform this request in your browser and verify the owner:

    https://yourOrg.crm4.dynamics.com/api/data/v9.2/accounts(b17834c2-83c4-eb11-bacc-000d3a9d4415)?$select=name&$expand=owninguser($select=fullname)

    You will get something like: 

    pastedimage1622738666402v1.png

    If you got a null value like below. This means that your record is assigned to a team !

    pastedimage1622738840127v2.png

    In this case, you need to perform the following request: 

    https://yourOrg.crm4.dynamics.com/api/data/v9.2/accounts(b17834c2-83c4-eb11-bacc-000d3a9d4415)?$select=name&$expand=owningteam($select=name)

    And, you will get something like: 

    pastedimage1622738968018v3.png

  • JDCv2.0 Profile Picture
    25 on at

    Thanks for the quick and helpful reply!

    I performed the first request you suggested and verified there is an owner for the record:

    {

    "@odata.context":"myOrg.crm.dynamics.com/.../$metadata

    "@odata.etag":"W/\"5432087\"",

    "name":"TEST ACCOUNT",

    "accountid":"b17834c2-83c4-eb11-bacc-000d3a9d4415",

    "owninguser":{

    "@odata.etag":"W/\"5146454\"",

    "fullname":"myOrg Platform",

    "systemuserid":"e3122b2b-59bf-eb11-8236-000d3a100d4b",

    "ownerid":"e3122b2b-59bf-eb11-8236-000d3a100d4b"

    }

    }

    I then performed the second request and see the team is null:

    {

    "@odata.context":"myOrg.crm.dynamics.com/.../$metadata

    "@odata.etag":"W/\"5432087\"",

    "name":"TEST ACCOUNT",

    "accountid":"b17834c2-83c4-eb11-bacc-000d3a9d4415",

    "owningteam":null

    }

    I assume I will need to assign the record to the appropriate team?

    </jdc>

  • kailashr2k6 Profile Picture
    50 on at

    Might as well check if you are using a different account to create using the API. As you mentioned it is not listed in the My Accounts view, if you are using another credentials to create the record then that person or the application user is the owner of the record and it won't be shown in that view. 

    Firstly check in the active accounts view, if it is there then the record is created and it will the owner or the access rights issue.

  • JDCv2.0 Profile Picture
    25 on at

    For clarification: this is a server API operation performed by an application user, so there is not a way (to my knowledge) to check the accounts view for an application user.

    It would seem the solution, based on Mehdi's reply is to assign the record to the specific team, although I am not sure if this is possible via REST API calls.

  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi,

    Maybe you can perform your operation on behalf of another user. Please refer to "Impersonate another user using the Web API" docs: docs.microsoft.com/.../impersonate-another-user-web-api

    Also, you can create a record and assign it to a user or a team at the same time:

    var entity = {};
    entity["ownerid@odata.bind"] = "/teams(7DCF0F24-D09D-EB11-B1AC-000D3A227E4B)";
    entity.name = "test account";
    
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/accounts", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "return=representation");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 201) {
                var uri = this.getResponseHeader("OData-EntityId");
                var regExp = /\(([^)] )\)/;
                var matches = regExp.exec(uri);
                var newEntityId = matches[1];
                //Handle returned attributes
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));

  • JDCv2.0 Profile Picture
    25 on at

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

  • JDCv2.0 Profile Picture
    25 on at

    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. 

  • meelamri Profile Picture
    13,218 User Group Leader on at

    Please share your Java Code.

  • JDCv2.0 Profile Picture
    25 on at

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

  • JDCv2.0 Profile Picture
    25 on at

    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"

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

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 59

#2
Manoj - ManoVerse Profile Picture

Manoj - ManoVerse 50 Super User 2026 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans