Tip #757: Passing enumerated values to Web API

Passing valuesShiny Dynamics CRM Web API has a number of useful functions that you can call using simple GET. Like ubiquitous WhoAmI: https://notarealorg.api.crm.dynamics.com/
api/data/v8.1/WhoAmI
,
nifty RetrieveOrganizationResources: https://stillnotarealorg.api.crm.dynamics.com
/api/data/v8.1/RetrieveOrganizationResources
,
or canny RetrieveDataEncryptionKey: https://yesthisisarealorg.api.crm.dynamics.com/
api/data/v8.1/RetrieveDataEncryptionKey
.

Some of these functions require parameters and documentation how to pass parameters is available. Except that the documentation does not explain how to deal with enumerated types required by some of the functions, e.g. RetrieveCurrentOrganization that needs AccessMode of EndpointAccessType enumerated type.

Web API implements OData version 4, and sample from the OData team to the rescue. General pattern is Namespace.Type’Value’. For example, if I want to retrieve org details external access type then URL will be https://noitwasnot.api.crm.dynamics.com/api/data/v8.1/
RetrieveCurrentOrganization(
AccessType=Microsoft.Dynamics.CRM.EndpointAccessType’Internet’)
with the output similar to:

{
  "@odata.context":"https://really.api.crm.dynamics.com/
     api/data/v8.1/$metadata#Microsoft.Dynamics.CRM
	 .RetrieveCurrentOrganizationResponse",
  "Detail":{
    "OrganizationId":"02745e7c-dead-beef-9058-bbe5bd989627",
    "FriendlyName":"Contoso",
    "OrganizationVersion":"8.1.0.452",
    "UrlName":"notagain",
    "UniqueName":"org12345678",
    "Endpoints":{
        "Count":3,
        "IsReadOnly":false,
        "Keys":[
			"WebApplication",
			"OrganizationService",
			"OrganizationDataService"
        ],
        "Values":[	  
            "https://foo.crm6.dynamics.com/",
            "https://bar.api.crm.dynamics.com/XRMServices/2011/Organization.svc",
            "https://baz.api.crm.dynamics.com/XRMServices/2011/OrganizationData.svc"
        ]
    },
    "State":"Enabled"
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *