|
| 1 | +# Modify existing code to use Global Discovery Web API |
| 2 | + |
| 3 | +The Discovery Service Web API can be used to discover instances for your users. If you currently use Organization Service SDK to discover your instances, you can follow the steps in this document to start consuming the Web API. |
| 4 | +A detailed description of the Web API can be found on the [Discovery Service Web API](/powerapps/developer/common-data-service/webapi/discover-url-organization-web-api) page. |
| 5 | + |
| 6 | +If you currently use the Web API, it is recommended that you make sure to point to the Global Discovery service endpoint (https://globaldisco.crm.dynamics.com) of the Discovery service. |
| 7 | +The rest of this document describes the changes that might be needed to use the Web API |
| 8 | + |
| 9 | +## Authentication |
| 10 | +The Discovery Service Web API supports authentication with OAuth 2.0 access tokens. |
| 11 | +If your code uses WS-Trust SAML tokens, you will need to change code acquire OAuth 2.0 token from Azure AD, and pass it to the Global Discovery Service Web API call. |
| 12 | + |
| 13 | +## OData API calls |
| 14 | +The calls below are supported by the Web API. These follow the OData v4 standard and |
| 15 | +The Instances API replaces both RetrieveOrganizations and RetrieveOrganization based on the desired scenario and returns the same data. |
| 16 | + |
| 17 | +- Get all instances for the user. |
| 18 | +```http |
| 19 | +GET https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances |
| 20 | +``` |
| 21 | +Response |
| 22 | +```javascript |
| 23 | +{ |
| 24 | + "value":[ |
| 25 | + { |
| 26 | + "Id":"<GUID>", |
| 27 | + "UniqueName":"myorg", |
| 28 | + "UrlName":"orgurlname", |
| 29 | + "FriendlyName":"My Org", |
| 30 | + "State":0, |
| 31 | + "Version":"<Version>", |
| 32 | + "Url":"https://orgurlname.crm.dynamics.com", |
| 33 | + "ApiUrl":"https://orgurlname.api.crm.dynamics.com" |
| 34 | + } |
| 35 | + ] |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +- Get a single instance by id |
| 40 | +```http |
| 41 | +GET https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances(<guid>) |
| 42 | +``` |
| 43 | +- Get a single instance by name |
| 44 | +```http |
| 45 | +GET https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances(UniqueName='myorg') |
| 46 | +``` |
| 47 | + |
| 48 | +Response |
| 49 | +```javascript |
| 50 | +{ |
| 51 | + "Id":"<GUID>", |
| 52 | + "UniqueName":"myorg", |
| 53 | + "UrlName":"orgurlname", |
| 54 | + "FriendlyName":"My Org", |
| 55 | + "State":0, |
| 56 | + "Version":"<Version>", |
| 57 | + "Url":"https://orgurlname.crm.dynamics.com", |
| 58 | + "ApiUrl":"https://orgurlname.api.crm.dynamics.com" |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +## Mapping of fields |
| 63 | +The fields from the response of the WCF discovery service endpoint can be mapped as below to the Web API endpoint, these are applicable to all above calls. |
| 64 | + |
| 65 | +Organization Service response field | Discovery Web API response field |
| 66 | +------------------------------------|--------------------------------- |
| 67 | +Endpoints[WebApplication] | Url |
| 68 | +Endpoints[OrganizationService] | {ApiUrl}/XRMServices/2011/Organization.svc |
| 69 | +Endpoints[OrganizationDataService] |{ApiUrl}//XRMServices/2011/OrganizationData.svc |
| 70 | +FriendlyName|FriendlyName |
| 71 | +OrganizationId|Id |
| 72 | +OrganizationVersion|Version |
| 73 | +State | State<br/><ul><li>0: Enabled</li><li>1: Disabled</li><ul> |
| 74 | +UniqueName|UniqueName |
| 75 | +UrlName|UrlName |
| 76 | + |
| 77 | +## Deprecated API call |
| 78 | +The WCF SDK call GetUserIdByExternalId is not supported in the Web API. |
| 79 | + |
| 80 | +## See Also |
| 81 | +[Discovery Services](/powerapps/developer/common-data-service/discovery-service) |
| 82 | + |
| 83 | +[Use the Common Data Service Web API](/powerapps/developer/common-data-service/webapi/discover-url-organization-web-api) |
0 commit comments