简体   繁体   中英

How to get the details about the contact/account fields along with their types using Web API in Dynamics 365?

I am fairly new to Dynamics 365 and currently trying to get the details about the contact fields (the name of the field and the field type - String, Boolean, Int32 etc. mainly) - in other words, the properties that are listed over here: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/contact?view=dynamics-ce-odata-9 - through the web API but I am unable to find any relevant documentation.

The only place where I can find these details is from the metadata endpoint - api/data/v9.0/$metadata#contacts -

<EntityType Name="account" BaseType="mscrm.crmbaseentity">
<Key>
<PropertyRef Name="accountid"/>
</Key>
<Property Name="territorycode" Type="Edm.Int32"/>
<Property Name="lastusedincampaign" Type="Edm.DateTimeOffset"/>
<Property Name="_msdyn_preferredresource_value" Type="Edm.Guid"/>
<Property Name="address1_name" Type="Edm.String" Unicode="false"/>
<Property Name="timezoneruleversionnumber" Type="Edm.Int32"/>
<Property Name="_owningbusinessunit_value" Type="Edm.Guid"/>
<Property Name="overriddencreatedon" Type="Edm.DateTimeOffset"/>
<Property Name="address1_telephone3" Type="Edm.String" Unicode="false"/>
<Property Name="entityimageid" Type="Edm.Guid"/>
<Property Name="ownershipcode" Type="Edm.Int32"/>
<Property Name="customersizecode" Type="Edm.Int32"/>
<Property Name="_primarycontactid_value" Type="Edm.Guid"/>
<Property Name="creditlimit" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="entityimage_url" Type="Edm.String" Unicode="false"/>
<Property Name="versionnumber" Type="Edm.Int64"/>
<Property Name="_territoryid_value" Type="Edm.Guid"/>
<Property Name="entityimage_timestamp" Type="Edm.Int64"/>
<Property Name="telephone3" Type="Edm.String" Unicode="false"/>
<Property Name="donotbulkpostalmail" Type="Edm.Boolean"/>
<Property Name="address1_freighttermscode" Type="Edm.Int32"/>
<Property Name="address1_postofficebox" Type="Edm.String" Unicode="false"/>
<Property Name="address1_fax" Type="Edm.String" Unicode="false"/>
<Property Name="onholdtime" Type="Edm.Int32"/>
<Property Name="_defaultpricelevelid_value" Type="Edm.Guid"/>
<Property Name="telephone2" Type="Edm.String" Unicode="false"/>
<Property Name="opendeals" Type="Edm.Int32"/>
<Property Name="shippingmethodcode" Type="Edm.Int32"/>
<Property Name="address1_addressid" Type="Edm.Guid"/>
<Property Name="new_fdaccount" Type="Edm.String" Unicode="false"/>
<Property Name="address1_composite" Type="Edm.String" Unicode="false"/>
<Property Name="_createdonbehalfby_value" Type="Edm.Guid"/>
<Property Name="address2_city" Type="Edm.String" Unicode="false"/>
<Property Name="address2_latitude" Type="Edm.Double"/>
<Property Name="entityimage" Type="Edm.Binary"/>
<Property Name="opendeals_state" Type="Edm.Int32"/>
<Property Name="address1_telephone2" Type="Edm.String" Unicode="false"/>
<Property Name="aging90_base" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="address2_postalcode" Type="Edm.String" Unicode="false"/>
<Property Name="address2_name" Type="Edm.String" Unicode="false"/>
<Property Name="primarysatoriid" Type="Edm.String" Unicode="false"/>
<Property Name="_owningteam_value" Type="Edm.Guid"/>
<Property Name="_masterid_value" Type="Edm.Guid"/>
<Property Name="accountnumber" Type="Edm.String" Unicode="false"/>
<Property Name="aging30" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="msdyn_travelchargetype" Type="Edm.Int32"/>
<Property Name="address2_county" Type="Edm.String" Unicode="false"/>
<Property Name="donotbulkemail" Type="Edm.Boolean"/>
<Property Name="_originatingleadid_value" Type="Edm.Guid"/>
<Property Name="emailaddress3" Type="Edm.String" Unicode="false"/>
<Property Name="_modifiedbyexternalparty_value" Type="Edm.Guid"/>
<Property Name="paymenttermscode" Type="Edm.Int32"/>
<Property Name="websiteurl" Type="Edm.String" Unicode="false"/>
<Property Name="revenue" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="merged" Type="Edm.Boolean"/>
<Property Name="address1_shippingmethodcode" Type="Edm.Int32"/>
<Property Name="description" Type="Edm.String" Unicode="false"/>
<Property Name="address2_line1" Type="Edm.String" Unicode="false"/>
<Property Name="aging30_base" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="address1_stateorprovince" Type="Edm.String" Unicode="false"/>
<Property Name="lastonholdtime" Type="Edm.DateTimeOffset"/>
<Property Name="sharesoutstanding" Type="Edm.Int32"/>
<Property Name="sic" Type="Edm.String" Unicode="false"/>
<Property Name="marketcap" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="_owninguser_value" Type="Edm.Guid"/>
<Property Name="_msdyn_workhourtemplate_value" Type="Edm.Guid"/>
<Property Name="_ownerid_value" Type="Edm.Guid"/>
<Property Name="address2_addressid" Type="Edm.Guid"/>
<Property Name="address2_telephone1" Type="Edm.String" Unicode="false"/>
<Property Name="msdyn_travelcharge" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="address1_primarycontactname" Type="Edm.String" Unicode="false"/>
<Property Name="openrevenue" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="statecode" Type="Edm.Int32"/>
<Property Name="address1_latitude" Type="Edm.Double"/>
<Property Name="_msdyn_salestaxcode_value" Type="Edm.Guid"/>
<Property Name="donotfax" Type="Edm.Boolean"/>
<Property Name="msdyn_workorderinstructions" Type="Edm.String" Unicode="false"/>
<Property Name="address1_county" Type="Edm.String" Unicode="false"/>
<Property Name="address2_telephone3" Type="Edm.String" Unicode="false"/>
<Property Name="_transactioncurrencyid_value" Type="Edm.Guid"/>
<Property Name="_preferredserviceid_value" Type="Edm.Guid"/>
<Property Name="accountratingcode" Type="Edm.Int32"/>
<Property Name="msdyn_travelcharge_base" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="stageid" Type="Edm.Guid"/>
<Property Name="address2_composite" Type="Edm.String" Unicode="false"/>
<Property Name="utcconversiontimezonecode" Type="Edm.Int32"/>
<Property Name="donotemail" Type="Edm.Boolean"/>
<Property Name="aging60" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="customertypecode" Type="Edm.Int32"/>
<Property Name="telephone1" Type="Edm.String" Unicode="false"/>
<Property Name="_createdby_value" Type="Edm.Guid"/>
<Property Name="address2_longitude" Type="Edm.Double"/>
<Property Name="marketingonly" Type="Edm.Boolean"/>
<Property Name="_modifiedby_value" Type="Edm.Guid"/>
<Property Name="yominame" Type="Edm.String" Unicode="false"/>
<Property Name="address2_primarycontactname" Type="Edm.String" Unicode="false"/>
<Property Name="openrevenue_date" Type="Edm.DateTimeOffset"/>
<Property Name="address2_country" Type="Edm.String" Unicode="false"/>
<Property Name="address1_line2" Type="Edm.String" Unicode="false"/>
<Property Name="donotsendmm" Type="Edm.Boolean"/>
<Property Name="address1_postalcode" Type="Edm.String" Unicode="false"/>
<Property Name="traversedpath" Type="Edm.String" Unicode="false"/>
<Property Name="numberofemployees" Type="Edm.Int32"/>
<Property Name="tickersymbol" Type="Edm.String" Unicode="false"/>
<Property Name="address1_city" Type="Edm.String" Unicode="false"/>
<Property Name="aging90" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="address1_longitude" Type="Edm.Double"/>
<Property Name="participatesinworkflow" Type="Edm.Boolean"/>
<Property Name="revenue_base" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="creditonhold" Type="Edm.Boolean"/>
<Property Name="address1_telephone1" Type="Edm.String" Unicode="false"/>
<Property Name="createdon" Type="Edm.DateTimeOffset"/>
<Property Name="name" Type="Edm.String" Unicode="false"/>
<Property Name="exchangerate" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="address2_addresstypecode" Type="Edm.Int32"/>
<Property Name="address2_line2" Type="Edm.String" Unicode="false"/>
<Property Name="address1_upszone" Type="Edm.String" Unicode="false"/>
<Property Name="msdyn_externalaccountid" Type="Edm.String" Unicode="false"/>
<Property Name="primarytwitterid" Type="Edm.String" Unicode="false"/>
<Property Name="timespentbymeonemailandmeetings" Type="Edm.String" Unicode="false"/>
<Property Name="openrevenue_state" Type="Edm.Int32"/>
<Property Name="address1_line1" Type="Edm.String" Unicode="false"/>
<Property Name="accountid" Type="Edm.Guid"/>
<Property Name="_slaid_value" Type="Edm.Guid"/>
<Property Name="ftpsiteurl" Type="Edm.String" Unicode="false"/>
<Property Name="followemail" Type="Edm.Boolean"/>
<Property Name="address2_freighttermscode" Type="Edm.Int32"/>
<Property Name="donotphone" Type="Edm.Boolean"/>
<Property Name="accountclassificationcode" Type="Edm.Int32"/>
<Property Name="donotpostalmail" Type="Edm.Boolean"/>
<Property Name="_preferredequipmentid_value" Type="Edm.Guid"/>
<Property Name="teamsfollowed" Type="Edm.Int32"/>
<Property Name="processid" Type="Edm.Guid"/>
<Property Name="address2_telephone2" Type="Edm.String" Unicode="false"/>
<Property Name="address1_addresstypecode" Type="Edm.Int32"/>
<Property Name="address1_utcoffset" Type="Edm.Int32"/>
<Property Name="_parentaccountid_value" Type="Edm.Guid"/>
<Property Name="_msdyn_serviceterritory_value" Type="Edm.Guid"/>
<Property Name="_createdbyexternalparty_value" Type="Edm.Guid"/>
<Property Name="address2_fax" Type="Edm.String" Unicode="false"/>
<Property Name="businesstypecode" Type="Edm.Int32"/>
<Property Name="aging60_base" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="_modifiedonbehalfby_value" Type="Edm.Guid"/>
<Property Name="address2_shippingmethodcode" Type="Edm.Int32"/>
<Property Name="stockexchange" Type="Edm.String" Unicode="false"/>
<Property Name="msdyn_taxexemptnumber" Type="Edm.String" Unicode="false"/>
<Property Name="preferredappointmentdaycode" Type="Edm.Int32"/>
<Property Name="creditlimit_base" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="address1_line3" Type="Edm.String" Unicode="false"/>
<Property Name="_msdyn_billingaccount_value" Type="Edm.Guid"/>
<Property Name="preferredcontactmethodcode" Type="Edm.Int32"/>
<Property Name="fax" Type="Edm.String" Unicode="false"/>
<Property Name="openrevenue_base" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="statuscode" Type="Edm.Int32"/>
<Property Name="address2_upszone" Type="Edm.String" Unicode="false"/>
<Property Name="_slainvokedid_value" Type="Edm.Guid"/>
<Property Name="opendeals_date" Type="Edm.DateTimeOffset"/>
<Property Name="address1_country" Type="Edm.String" Unicode="false"/>
<Property Name="modifiedon" Type="Edm.DateTimeOffset"/>
<Property Name="address2_line3" Type="Edm.String" Unicode="false"/>
<Property Name="address2_postofficebox" Type="Edm.String" Unicode="false"/>
<Property Name="address2_utcoffset" Type="Edm.Int32"/>
<Property Name="msdyn_taxexempt" Type="Edm.Boolean"/>
<Property Name="emailaddress1" Type="Edm.String" Unicode="false"/>
<Property Name="_preferredsystemuserid_value" Type="Edm.Guid"/>
<Property Name="address2_stateorprovince" Type="Edm.String" Unicode="false"/>
<Property Name="preferredappointmenttimecode" Type="Edm.Int32"/>
<Property Name="emailaddress2" Type="Edm.String" Unicode="false"/>
<Property Name="marketcap_base" Type="Edm.Decimal" Scale="Variable"/>
<Property Name="importsequencenumber" Type="Edm.Int32"/>
<Property Name="industrycode" Type="Edm.Int32"/>
<Property Name="accountcategorycode" Type="Edm.Int32"/>

but this returns the whole metadata as XML which contain a lot of unnecessary information. Is there any way I can retrieve this information as JSON?

may be this is helpful for you Converting XMLto JSON :-

http://goessner.net/download/prj/jsonxml/

also you can add this https://github.com/abdmob/x2js This library provides XML to JSON (JavaScript Objects) and vice versa javascript conversion functions.The library is very small and doesn't require any other additional libraries. Demo on http://jsfiddle.net/abdmob/gkxucxrj/1/

Normally we will use XrmToolBox Metadata browser to explore the entity/attribute metadata. You can find some browser addin too.

If you want to download the schema metadata, you can go to Settings - Customizations - Developer resources and download the huge xml file.

When you need the Json metadata in code use the below web api endpoint:

clientURL + "api/data/v9.0/EntityDefinitions(LogicalName='contact')/Attributes"

Read more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM