Exemples de données de requête d’API Web

Utilisez ce groupe d’exemples de code pour en savoir plus sur la manière d’interroger les données avec l’API web Microsoft Dataverse. Cet exemple est mis en œuvre comme un projet distinct pour les langues suivantes :

Cette rubrique décrit un ensemble commun d’opérations mises en œuvre par chaque exemple de ce groupe. Cette rubrique décrit les demandes et les réponses HTTP et la sortie texte que chaque exemple de ce groupe effectuera sans détails spécifiques à la langue. Affichez les descriptions spécifiques à la langue et les exemples individuels pour plus d’informations sur la façon dont ces opérations sont effectuées.

Montre ce qui suit

Cet exemple est composé des principales sections suivantes, qui contiennent les opérations de données de requête de l’API Web qui sont décrites plus en détail dans les rubriques conceptuelles associées.

Section de la rubrique Rubrique(s) associée(s)
Section 1 : Sélection des propriétés spécifiques Récupérer des propriétés spécifiques
Valeurs formatées
Section 2 : Utilisation des fonctions de requête Filtrer les lignes
Utiliser les fonctions de requête OData
Composer une requête avec des fonctions
Web API Query Function Reference
Section 3 : Classement et alias Ordonner les lignes
Filtrer les lignes
Section 4 : Limiter et compter les résultats Limiter le nombre de lignes
Compter le nombre de lignes
Section 5 : Pagination Résultats de la page
Section 6 : Développement des résultats Joindre des tables
Section 7 : Agréger les résultats Données agrégées
Section 8 : FetchXML requêtes Référence FetchXml
Interroger des données à l’aide de FetchXml
Section 9 : Utilisation des requêtes prédéfinies Extraire et exécuter des requêtes prédéfinies
userquery EntityType
savedquery EntityType
Section 10 : Supprimer des exemples d’enregistrements Suppression de base
Exécuter des opérations par lots à l’aide de l’API Web

Les sections suivantes contiennent un bref examen des opérations de l’API web Dataverse effectuées, ainsi que les messages HTTP et la sortie de la console associée correspondants.

Section 0 : Création d’enregistrements à interroger

L’exemple de code crée un ensemble d’exemples de lignes à interroger. Le code supprime les données à la fin, sauf si vous choisissez de les conserver. Vous pouvez obtenir des résultats différents en fonction de toutes les données existantes dans votre environnement.

Les données sont ajoutées à l’aide de l’insertion profonde dans une requête POST simple et correspond à la structure suivante :

{
  "name": "Contoso, Ltd. (sample)",
  "Account_Tasks": [
    {
      "subject": "Task 1 for Contoso, Ltd.",
      "description": "Task 1 for Contoso, Ltd. description",
      "actualdurationminutes": 10
    },
    {
      "subject": "Task 2 for Contoso, Ltd.",
      "description": "Task 2 for Contoso, Ltd. description",
      "actualdurationminutes": 10
    },
    {
      "subject": "Task 3 for Contoso, Ltd.",
      "description": "Task 3 for Contoso, Ltd. description",
      "actualdurationminutes": 10
    }
  ],
  "primarycontactid": {
    "firstname": "Yvonne",
    "lastname": "McKay (sample)",
    "jobtitle": "Coffee Master",
    "annualincome": 45000,
    "Contact_Tasks": [
      {
        "subject": "Task 1 for Yvonne McKay",
        "description": "Task 1 for Yvonne McKay description",
        "actualdurationminutes": 5
      },
      {
        "subject": "Task 2 for Yvonne McKay",
        "description": "Task 2 for Yvonne McKay description",
        "actualdurationminutes": 5
      },
      {
        "subject": "Task 3 for Yvonne McKay",
        "description": "Task 3 for Yvonne McKay description",
        "actualdurationminutes": 5
      }
    ]
  },
  "contact_customer_accounts": [
    {
      "firstname": "Susanna",
      "lastname": "Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome": 52000,
      "Contact_Tasks": [
        {
          "subject": "Task 1 for Susanna Stubberod",
          "description": "Task 1 for Susanna Stubberod description",
          "actualdurationminutes": 3
        },
        {
          "subject": "Task 2 for Susanna Stubberod",
          "description": "Task 2 for Susanna Stubberod description",
          "actualdurationminutes": 3
        },
        {
          "subject": "Task 3 for Susanna Stubberod",
          "description": "Task 3 for Susanna Stubberod description",
          "actualdurationminutes": 3
        }
      ]
    },
    {
      "firstname": "Nancy",
      "lastname": "Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome": 55500,
      "Contact_Tasks": [
        {
          "subject": "Task 1 for Nancy Anderson",
          "description": "Task 1 for Nancy Anderson description",
          "actualdurationminutes": 4
        },
        {
          "subject": "Task 2 for Nancy Anderson",
          "description": "Task 2 for Nancy Anderson description",
          "actualdurationminutes": 4
        },
        {
          "subject": "Task 3 for Nancy Anderson",
          "description": "Task 3 for Nancy Anderson description",
          "actualdurationminutes": 4
        }
      ]
    },
    {
      "firstname": "Maria",
      "lastname": "Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome": 31000,
      "Contact_Tasks": [
        {
          "subject": "Task 1 for Maria Cambell",
          "description": "Task 1 for Maria Cambell description",
          "actualdurationminutes": 5
        },
        {
          "subject": "Task 2 for Maria Cambell",
          "description": "Task 2 for Maria Cambell description",
          "actualdurationminutes": 5
        },
        {
          "subject": "Task 3 for Maria Cambell",
          "description": "Task 3 for Maria Cambell description",
          "actualdurationminutes": 5
        }
      ]
    },
    {
      "firstname": "Scott",
      "lastname": "Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome": 38000,
      "Contact_Tasks": [
        {
          "subject": "Task 1 for Scott Konersmann",
          "description": "Task 1 for Scott Konersmann description",
          "actualdurationminutes": 6
        },
        {
          "subject": "Task 2 for Scott Konersmann",
          "description": "Task 2 for Scott Konersmann description",
          "actualdurationminutes": 6
        },
        {
          "subject": "Task 3 for Scott Konersmann",
          "description": "Task 3 for Scott Konersmann description",
          "actualdurationminutes": 6
        }
      ]
    },
    {
      "firstname": "Robert",
      "lastname": "Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome": 78000,
      "Contact_Tasks": [
        {
          "subject": "Task 1 for Robert Lyon",
          "description": "Task 1 for Robert Lyon description",
          "actualdurationminutes": 7
        },
        {
          "subject": "Task 2 for Robert Lyon",
          "description": "Task 2 for Robert Lyon description",
          "actualdurationminutes": 7
        },
        {
          "subject": "Task 3 for Robert Lyon",
          "description": "Task 3 for Robert Lyon description",
          "actualdurationminutes": 7
        }
      ]
    },
    {
      "firstname": "Paul",
      "lastname": "Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome": 68500,
      "Contact_Tasks": [
        {
          "subject": "Task 1 for Paul Cannon",
          "description": "Task 1 for Paul Cannon description",
          "actualdurationminutes": 8
        },
        {
          "subject": "Task 2 for Paul Cannon",
          "description": "Task 2 for Paul Cannon description",
          "actualdurationminutes": 8
        },
        {
          "subject": "Task 3 for Paul Cannon",
          "description": "Task 3 for Paul Cannon description",
          "actualdurationminutes": 8
        }
      ]
    },
    {
      "firstname": "Rene",
      "lastname": "Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome": 86000,
      "Contact_Tasks": [
        {
          "subject": "Task 1 for Rene Valdes",
          "description": "Task 1 for Rene Valdes description",
          "actualdurationminutes": 9
        },
        {
          "subject": "Task 2 for Rene Valdes",
          "description": "Task 2 for Rene Valdes description",
          "actualdurationminutes": 9
        },
        {
          "subject": "Task 3 for Rene Valdes",
          "description": "Task 3 for Rene Valdes description",
          "actualdurationminutes": 9
        }
      ]
    },
    {
      "firstname": "Jim",
      "lastname": "Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome": 81400,
      "Contact_Tasks": [
        {
          "subject": "Task 1 for Jim Glynn",
          "description": "Task 1 for Jim Glynn description",
          "actualdurationminutes": 10
        },
        {
          "subject": "Task 2 for Jim Glynn",
          "description": "Task 2 for Jim Glynn description",
          "actualdurationminutes": 10
        },
        {
          "subject": "Task 3 for Jim Glynn",
          "description": "Task 3 for Jim Glynn description",
          "actualdurationminutes": 10
        }
      ]
    }
  ]
}  

Section 1 : Sélection des propriétés spécifiques

Incluez toujours l’option de requête $select dans vos requêtes. Si vous ne le faites pas, le serveur renvoie toutes les propriétés de chaque ligne de la table, ce qui réduit les performances. Apprenez à créer des colonnes Sélectionner.

Cet exemple montre comment créer une requête de base en sélectionnant trois propriétés d’un contact EntityType. Les propriétés sont fullname, jobtitle, annualincome. La section illustre également les différences entre formaté et les valeurs non formatées telles qu’elles apparaissent dans les résultats du contact annualincome propriété.

Dans cet exemple, nous interrogeons un contact spécifique. Dans ce cas, il s’agit du contact principal du compte, Yvonne McKay (sample).

Demande :

GET [Organization Uri]/api/data/v9.2/contacts(81716234-9628-ed11-9db1-000d3a320482)?$select=fullname,jobtitle,annualincome HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
ETag: W/"1146626"
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)/$entity",
  "@odata.etag": "W/\"1146626\"",
  "fullname": "Yvonne McKay (sample)",
  "jobtitle": "Coffee Master",
  "annualincome@OData.Community.Display.V1.FormattedValue": "$45,000.00",
  "annualincome": 45000.0,
  "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
  "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
  "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
  "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
  "contactid": "81716234-9628-ed11-9db1-000d3a320482"
}

Sortie de la console :

Contact basic info:
        Fullname: Yvonne McKay (sample)
        Jobtitle: Coffee Master
        Annualincome (unformatted): 45000
        Annualincome (formatted): $45,000.00  

Section 2 : Utilisation des fonctions de requête

Utilisez les options de filtre pour définir les critères des résultats escomptés. Vous pouvez générer des filtres simple à complexes à l’aide d’une combinaison de fonctions de requête, d’opérateurs de comparaison, et d’opérateurs logiques. Plus d’information: Filtrer les lignes

Les fonctions de requête sont des fonctions qui peuvent être utilisées comme un critère de filtre dans une requête. Ces fonctions acceptent des paramètres et renvoient une valeur Boolean. Il existe des fonctions de requête standard et des fonctions de requête spécifique Dataverse. Cet exemple illustre comment créer une requête pour chaque type.

Fonctionnalités de requête standard

Dataverse prend en charge un petit sous-ensemble de fonctions de requête intégrées OData, notamment : contains, endswith, et startswith. Par exemple, la fonction standard de requête contains permet de filtrer les propriétés correspondant à une chaîne. Plus d’information: Utiliser les fonctions de requête OData

Dans cette opération, nous interrogeons l’ensemble des contacts dont fullname contenant la chaîne (sample).

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)') and _parentcustomerid_value eq 7d716234-9628-ed11-9db1-000d3a320482 HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contacts filtered by fullname containing '(sample)':
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

Fonctions de requête Dataverse

Les fonctions de requête Dataverse fournissent un grand nombre d’options pour créer des requêtes qui sont appropriées pour Dataverse. Pour obtenir une liste complète de ces fonctionnalités, voir Web API Query Function Reference. Pour plus d’informations, voir :Composer une requête avec des fonctions

Les fonctions de requête YDataverse sont similaires aux fonctions de requête standard. La principale différence est, lorsque vous utilisez des fonctions de requête Dataverse, que vous devez fournir le nom complet de la fonction y compris le(s) nom(s) de paramètre(s). Par exemple, pour obtenir la liste des contacts créés au cours de la dernière heure, vous pouvez créer une requête à l’aide de la fonction LastXHours.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=Microsoft.Dynamics.CRM.LastXHours(PropertyName=@p1,PropertyValue=@p2) and _parentcustomerid_value eq 7d716234-9628-ed11-9db1-000d3a320482&@p1='createdon'&@p2='1' HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contacts that were created within the last 1hr:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

Utiliser les opérateurs

Utiliser opérateurs de comparaison et Opérateurs logiques (eq,ne,gt,ge,lt,le,and,or,not) pour affiner davantage vos résultats. Dans cet exemple, nous interrogeons la liste de tous les contacts avec fullname contenant (sample) et un chiffre d’affaires annuel supérieur à 55000.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)') and annualincome gt 55000 and _parentcustomerid_value eq 7d716234-9628-ed11-9db1-000d3a320482 HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contacts with '(sample)' in name and income above $55,000:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

Définir la priorité

Comme tous les opérateurs ont la même priorité, utilisez des parenthèses pour établir l’ordre dans lequel les conditions de requête sont évaluées. Les filtres sont appliqués de gauche à droite. La commande dans laquelle ces instructions s’affichent dans le filtre peut affecter les résultats.

Dans cet exemple, nous interrogeons la liste de tous les contacts avec fullname contenant (sample), jobtitle contenant senior ou manager et annualincome supérieur à 55000. Pour obtenir les résultats qui nous intéressent, les crochets sont utilisés pour regrouper les filtres jobtitle ensemble. Si nous ne le faisons pas, l’opérateur or a la même priorité que les opérateurs and. Voici à quoi la requête de cet exemple ressemble : $filter=contains(fullname,'(sample)') and (contains(jobtitle,'senior') or contains(jobtitle,'manager')) and annualincome gt 55000.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)') and (contains(jobtitle, 'senior') or contains(jobtitle,'manager')) and annualincome gt 55000 and _parentcustomerid_value eq 7d716234-9628-ed11-9db1-000d3a320482 HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contacts with '(sample)' in name senior jobtitle or high income:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

Section 3 : Classement et alias

Classer les résultats

Pour trier les résultats dans l’ordre croissant ou décroissant, utilisez l’option de filtre $orderby. Dans cet exemple, nous interrogerons l’ensemble des contacts avec fullname contenant (sample) et demanderons les données dans l’ordre croissant sur la base de la valeur de propriété jobtitle puis dans l’ordre décroissant, sur la base de la valeur d’une propriété annualincome à l’aide de cette syntaxe : $orderby=jobtitle asc, annualincome desc. Plus d’information: Ordonner les lignes

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)') and _parentcustomerid_value eq 7d716234-9628-ed11-9db1-000d3a320482&$orderby=jobtitle asc, annualincome desc HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contacts ordered by jobtitle (Ascending) and annualincome (descending)
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00

Alias de paramètre

Utiliser alias de paramètres pour réutiliser plus facilement les paramètres dans vos filtres. Vous pouvez utiliser des alias dans les options $filter et $orderby . Si l’alias ne dispose pas d’une valeur, le système suppose qu’il est nul.

Vous pouvez également utiliser des alias de paramètre lorsque vous appelez des fonctionnalités. Par exemple, nous pouvons réécrire la requête dans l’opération des résultats de commande pour utiliser des paramètres et obtenir les mêmes résultats de sortie.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(@p1,'(sample)') and @p2 eq @p3&$orderby=@p4 asc, @p5 desc&@p1=fullname&@p2=_parentcustomerid_value&@p3=7d716234-9628-ed11-9db1-000d3a320482&@p4=jobtitle&@p5=annualincome HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contacts ordered by jobtitle (Ascending) and annualincome (descending)
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00

Section 4 : Limiter et compter les résultats

En tant que bonne pratique, ne renvoyez pas plus de données que nécessaire. Pour protéger les performances, le serveur renvoie un maximum de 5 000 lignes de table par requête.

Pour limiter le nombre de résultats renvoyés, Utilisez le $top option de requête ou ajouter odata.maxpagesize dans l’en-tête de la requête. L’option de requête $top renvoie le premier nombre de lignes du jeu de résultats et ignore le reste. L’en-tête de requête odata.maxpagesize spécifie le nombre de lignes renvoyées par page avec une propriété @odata.nextLink pour obtenir les résultats de la page suivante. En savoir plus sur les résultats de la page.

Meilleurs résultats

Nous pouvons appliquer l’option de requête $top pour limiter l’opération de requête de base aux cinq premiers contacts avec fullname contenant (sample). Dans ce cas, la demande produit réellement au moins 10 résultats, mais seuls les 5 premières entrées sont renvoyées dans la réponse.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)') and _parentcustomerid_value eq 7d716234-9628-ed11-9db1-000d3a320482&$top=5 HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contacts top 5 results:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00

Nombre de collections

Si vous souhaitez uniquement connaître le nombre d’enregistrements dans une collection, ajoutez /$count à l’URL de la collection. La valeur maximale est 5,000.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts/$count HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0

9

Sortie de la console :

The contacts collection has 9 contacts.

Nombre de résultats

Tu peux recevoir le nombre de lignes à partir d’une propriété de valeur de collection ou d’un nombre de lignes de table correspondantes dans un filtre. Le compte vous indique le nombre de lignes possibles dans votre résultat. Toutefois, le serveur Dataverse renvoie 5 000 comme nombre maximal, même si le résultat peut être supérieur.

Dans cet exemple, nous avons créé un filtre avec jobtitle contenant Senior ou Manager et nous avons également demandé un $count du résultat. La réponse contient le nombre dans la propriété @odata.count ainsi que les résultats de la requête.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=(contains(jobtitle,'senior') or contains(jobtitle, 'manager')) and _parentcustomerid_value eq 7d716234-9628-ed11-9db1-000d3a320482&$count=true HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@odata.count": 6,
  "@Microsoft.Dynamics.CRM.totalrecordcount": 6,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

6 Contacts with 'senior' or 'manager' in job title:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

Section 5 : Pagination

Certaines requêtes renvoient un grand nombre de lignes et il est plus facile de les afficher une page à la fois. À récupérer les résultats paginés, Utilisez le odata.maxpagesize option au lieu de $top.

Dans cet exemple, nous demandons un $count et nous définissons odata.maxpagesize sur 4. Ce filtre correspond à 10 contacts, mais nous en récupérons seulement 4 à la fois. Nous utilisons également le nombre et la taille maximum de la page pour connaître le nombre total de pages. Le résultat de la première page est renvoyé dans cette demande.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')&$count=true HTTP/1.1
Prefer: odata.maxpagesize=4; odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"; odata.maxpagesize=4

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@odata.count": 9,
  "@Microsoft.Dynamics.CRM.totalrecordcount": 9,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146626\"",
      "fullname": "Yvonne McKay (sample)",
      "jobtitle": "Coffee Master",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$45,000.00",
      "annualincome": 45000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "81716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    }
  ],
  "@odata.nextLink": "[Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')&$count=true&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%253e%253ccontactid%2520last%253d%2522%257b8D716234-9628-ED11-9DB1-000D3A320482%257d%2522%2520first%253d%2522%257b81716234-9628-ED11-9DB1-000D3A320482%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E"
}

Sortie de la console :

Contacts total: 9    Contacts per page: 4.
Page 1 of 3:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Yvonne McKay (sample)      |Coffee Master                      |$45,000.00
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00

Pour récupérer la page 2, utilisez une demande GET avec la valeur de la propriété @odata.nextLink.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')&$count=true&$skiptoken=<cookie pagenumber="2" pagingcookie="%3ccookie%20page%3d%221%22%3e%3ccontactid%20last%3d%22%7b8D716234-9628-ED11-9DB1-000D3A320482%7d%22%20first%3d%22%7b81716234-9628-ED11-9DB1-000D3A320482%7d%22%20%2f%3e%3c%2fcookie%3e" istracking="False" /> HTTP/1.1
Prefer: odata.maxpagesize=4; odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"; odata.maxpagesize=4

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome)",
  "@odata.count": 9,
  "@Microsoft.Dynamics.CRM.totalrecordcount": 9,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    }
  ],
  "@odata.nextLink": "[Organization Uri]/api/data/v9.2/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')&$count=true&$skiptoken=%3Ccookie%20pagenumber=%223%22%20pagingcookie=%22%253ccookie%2520page%253d%25222%2522%253e%253ccontactid%2520last%253d%2522%257b9D716234-9628-ED11-9DB1-000D3A320482%257d%2522%2520first%253d%2522%257b91716234-9628-ED11-9DB1-000D3A320482%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E"
}

Sortie de la console :

Page 2 of 3:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00

Section 6 : Développement des résultats

Pour récupérer des informations sur les lignes de table associées, utilisez l’option de requête $expand sur les propriétés de navigation. Plus d’informations : Joindre des tables

Développer la propriété de navigation à valeur unique

Une propriété de navigation à valeur unique représente une relation plusieurs-à-un. Dans nos exemples de données, le compte a une relation avec un contact via la colonne primarycontactid (attribut). Dans cette relation, le compte peut posséder un contact principal. À l’aide du compte EntityType, nous pouvons créer une requête pour obtenir des informations sur le compte et des informations développées sur son contact principal.

Demande :

GET [Organization Uri]/api/data/v9.2/accounts(7d716234-9628-ed11-9db1-000d3a320482)?$select=name&$expand=primarycontactid($select=fullname,jobtitle,annualincome) HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
ETag: W/"1146751"
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#accounts(name,primarycontactid(fullname,jobtitle,annualincome))/$entity",
  "@odata.etag": "W/\"1146751\"",
  "name": "Contoso, Ltd. (sample)",
  "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
  "primarycontactid": {
    "@odata.etag": "W/\"1146626\"",
    "fullname": "Yvonne McKay (sample)",
    "jobtitle": "Coffee Master",
    "annualincome@OData.Community.Display.V1.FormattedValue": "$45,000.00",
    "annualincome": 45000.0,
    "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
    "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
    "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
    "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
    "contactid": "81716234-9628-ed11-9db1-000d3a320482"
  }
}

Sortie de la console :

Account Contoso, Ltd. (sample) has the following primary contact person:
        Fullname: Yvonne McKay (sample)
        Jobtitle: Coffee Master
        Annualincome: 45000 

Développer la propriété partenaire

Chaque propriété de navigation possède une propriété « partenaire » correspondante. Une fois qu’une association est terminée, nous pouvons récupérer les informations via cette association. La colonne que nous utilisons dépend de la table de base sur laquelle la requête est basée.

Par exemple, dans l’opération précédente, nous avons créé une requête sur le type d’entité de compte. Nous voulions obtenir plus d’informations sur son contact principal, nous avons donc utilisé la colonne primarycontactid ou l’attribut. Si nous recherchons le type d’entité de compte, dans la section Propriétés de navigation à valeur unique, nous trouvons que la propriété partenaire de primarycontactid est la propriété de navigation avec une valeur de collection account_primary_contact, disponible dans le type d’entité de contact.

En écrivant une requête sur un contact, vous pouvez développer la colonne account_primary_contact pour obtenir des informations sur les comptes pour lesquels ce contact est le contact principal. Dans les exemples de données, Yvonne McKay (sample) est le contact principal d’un seul compte. Néanmoins, Yvonne peut éventuellement être attribuée à d’autres comptes comme contact principal. Parce que la propriété account_primary_contact a une relation plusieurs-à-un, le résultat est renvoyé sous la forme d’un tableau de lignes de compte.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts(81716234-9628-ed11-9db1-000d3a320482)?$select=fullname,jobtitle,annualincome&$expand=account_primary_contact($select=name) HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
ETag: W/"1146626"
OData-Version: 4.0

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome,account_primary_contact(name))/$entity",
  "@odata.etag": "W/\"1146626\"",
  "fullname": "Yvonne McKay (sample)",
  "jobtitle": "Coffee Master",
  "annualincome": 45000.0,
  "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
  "contactid": "81716234-9628-ed11-9db1-000d3a320482",
  "account_primary_contact": [
    {
      "@odata.etag": "W/\"1146751\"",
      "name": "Contoso, Ltd. (sample)",
      "accountid": "7d716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contact 'Yvonne McKay (sample)' is the primary contact for the following accounts:
        Contoso, Ltd. (sample)

Développez la propriété de navigation avec une valeur de collection

Les propriétés de navigation avec une valeur de collection prennent en charge les relations un-à-plusieurs ou plusieurs-à-plusieurs. Par exemple, dans nos exemples de données, le compte a une relation avec plusieurs contacts via la colonne contact_customer_accounts (attribut).

Nous pouvons utiliser le type d’entité de compte dans une requête pour obtenir des informations sur le compte et développer les informations sur ses contacts. Dans ce cas, Contoso, Ltd. (sample) est associé à neuf autres contacts via la propriété de navigation avec une valeur de collection contact_customer_accounts.

Demande :

GET [Organization Uri]/api/data/v9.2/accounts(7d716234-9628-ed11-9db1-000d3a320482)?$select=name&$expand=contact_customer_accounts($select=fullname,jobtitle,annualincome) HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
ETag: W/"1146751"
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#accounts(name,contact_customer_accounts(fullname,jobtitle,annualincome))/$entity",
  "@odata.etag": "W/\"1146751\"",
  "name": "Contoso, Ltd. (sample)",
  "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
  "contact_customer_accounts": [
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Account 'Contoso, Ltd. (sample)' has the following contact customers:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

Développez les propriétés de navigation multiples

Vous pouvez développer autant de propriétés de navigation que la requête a besoin. Toutefois, l’option $expand peut uniquement atteindre un niveau de profondeur.

Cet exemple développe les propriétés de navigation primarycontactid, contact_customer_accounts, et Account_Tasks du type d’entité de compte. Cette requête renvoie une réponse contenant des informations sur le compte et deux collections : une collection de contacts et une collection de tâches. L’exemple de code traite ces collections séparément.

Demande :

GET [Organization Uri]/api/data/v9.2/accounts(7d716234-9628-ed11-9db1-000d3a320482)?$select=name&$expand=primarycontactid($select=fullname,jobtitle,annualincome),contact_customer_accounts($select=fullname,jobtitle,annualincome),Account_Tasks($select=subject,description) HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
ETag: W/"1146751"
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#accounts(name,primarycontactid(fullname,jobtitle,annualincome),contact_customer_accounts(fullname,jobtitle,annualincome),Account_Tasks(subject,description))/$entity",
  "@odata.etag": "W/\"1146751\"",
  "name": "Contoso, Ltd. (sample)",
  "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
  "primarycontactid": {
    "@odata.etag": "W/\"1146626\"",
    "fullname": "Yvonne McKay (sample)",
    "jobtitle": "Coffee Master",
    "annualincome@OData.Community.Display.V1.FormattedValue": "$45,000.00",
    "annualincome": 45000.0,
    "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
    "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
    "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
    "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
    "contactid": "81716234-9628-ed11-9db1-000d3a320482"
  },
  "contact_customer_accounts": [
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ],
  "Account_Tasks": [
    {
      "@odata.etag": "W/\"1146746\"",
      "subject": "Task 1 for Contoso, Ltd.",
      "description": "Task 1 for Contoso, Ltd. description",
      "activityid": "7e716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146748\"",
      "subject": "Task 2 for Contoso, Ltd.",
      "description": "Task 2 for Contoso, Ltd. description",
      "activityid": "7f716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146750\"",
      "subject": "Task 3 for Contoso, Ltd.",
      "description": "Task 3 for Contoso, Ltd. description",
      "activityid": "80716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

-- Expanding multiple property types in one request --

Account Contoso, Ltd. (sample) has the following primary contact person:
        Fullname: Yvonne McKay (sample)
        Jobtitle: Coffee Master
        Annualincome: 45000

Account 'Contoso, Ltd. (sample)' has the following contact customers:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

Account 'Contoso, Ltd. (sample)' has the following tasks:
        Task 1 for Contoso, Ltd.
        Task 2 for Contoso, Ltd.
        Task 3 for Contoso, Ltd.

Extensions à plusieurs niveaux

Avec les propriétés de navigation à valeur unique, vous pouvez utiliser $expand pour continuer sur plusieurs niveaux en utilisant uniquement des propriétés de navigation à valeur unique. Cette requête commence par des enregistrements task et développe les données à partir des tables contact, account et systemuser utilisant uniquement des propriétés de navigation à valeur unique.

Demande :

GET [Organization Uri]/api/data/v9.2/tasks?$select=subject&$filter=regardingobjectid_contact_task/_accountid_value eq 7d716234-9628-ed11-9db1-000d3a320482&$expand=regardingobjectid_contact_task($select=fullname;$expand=parentcustomerid_account($select=name;$expand=createdby($select=fullname))) HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#tasks(subject,regardingobjectid_contact_task(fullname,parentcustomerid_account(name,createdby(fullname))))",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146775\"",
      "subject": "Task 1 for Susanna Stubberod",
      "activityid": "86716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Susanna Stubberod (sample)",
        "contactid": "85716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146777\"",
      "subject": "Task 2 for Susanna Stubberod",
      "activityid": "87716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Susanna Stubberod (sample)",
        "contactid": "85716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146779\"",
      "subject": "Task 3 for Susanna Stubberod",
      "activityid": "88716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Susanna Stubberod (sample)",
        "contactid": "85716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146781\"",
      "subject": "Task 1 for Nancy Anderson",
      "activityid": "8a716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Nancy Anderson (sample)",
        "contactid": "89716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146783\"",
      "subject": "Task 2 for Nancy Anderson",
      "activityid": "8b716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Nancy Anderson (sample)",
        "contactid": "89716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146785\"",
      "subject": "Task 3 for Nancy Anderson",
      "activityid": "8c716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Nancy Anderson (sample)",
        "contactid": "89716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146787\"",
      "subject": "Task 1 for Maria Cambell",
      "activityid": "8e716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Maria Cambell (sample)",
        "contactid": "8d716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146789\"",
      "subject": "Task 2 for Maria Cambell",
      "activityid": "8f716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Maria Cambell (sample)",
        "contactid": "8d716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146791\"",
      "subject": "Task 3 for Maria Cambell",
      "activityid": "90716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Maria Cambell (sample)",
        "contactid": "8d716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146793\"",
      "subject": "Task 1 for Scott Konersmann",
      "activityid": "92716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Scott Konersmann (sample)",
        "contactid": "91716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146795\"",
      "subject": "Task 2 for Scott Konersmann",
      "activityid": "93716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Scott Konersmann (sample)",
        "contactid": "91716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146797\"",
      "subject": "Task 3 for Scott Konersmann",
      "activityid": "94716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Scott Konersmann (sample)",
        "contactid": "91716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146799\"",
      "subject": "Task 1 for Robert Lyon",
      "activityid": "96716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Robert Lyon (sample)",
        "contactid": "95716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146801\"",
      "subject": "Task 2 for Robert Lyon",
      "activityid": "97716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Robert Lyon (sample)",
        "contactid": "95716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146803\"",
      "subject": "Task 3 for Robert Lyon",
      "activityid": "98716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Robert Lyon (sample)",
        "contactid": "95716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146806\"",
      "subject": "Task 1 for Paul Cannon",
      "activityid": "9a716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Paul Cannon (sample)",
        "contactid": "99716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146808\"",
      "subject": "Task 2 for Paul Cannon",
      "activityid": "9b716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Paul Cannon (sample)",
        "contactid": "99716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146810\"",
      "subject": "Task 3 for Paul Cannon",
      "activityid": "9c716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Paul Cannon (sample)",
        "contactid": "99716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146812\"",
      "subject": "Task 1 for Rene Valdes",
      "activityid": "9e716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Rene Valdes (sample)",
        "contactid": "9d716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146814\"",
      "subject": "Task 2 for Rene Valdes",
      "activityid": "9f716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Rene Valdes (sample)",
        "contactid": "9d716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146816\"",
      "subject": "Task 3 for Rene Valdes",
      "activityid": "a0716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Rene Valdes (sample)",
        "contactid": "9d716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146820\"",
      "subject": "Task 1 for Jim Glynn",
      "activityid": "a2716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Jim Glynn (sample)",
        "contactid": "a1716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146822\"",
      "subject": "Task 2 for Jim Glynn",
      "activityid": "a3716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Jim Glynn (sample)",
        "contactid": "a1716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    },
    {
      "@odata.etag": "W/\"1146827\"",
      "subject": "Task 3 for Jim Glynn",
      "activityid": "a4716234-9628-ed11-9db1-000d3a320482",
      "regardingobjectid_contact_task": {
        "fullname": "Jim Glynn (sample)",
        "contactid": "a1716234-9628-ed11-9db1-000d3a320482",
        "parentcustomerid_account": {
          "name": "Contoso, Ltd. (sample)",
          "accountid": "7d716234-9628-ed11-9db1-000d3a320482",
          "createdby": {
            "fullname": "FirstName Lastname",
            "systemuserid": "ce939f72-a724-ed11-b83e-00224804438a",
            "ownerid": "ce939f72-a724-ed11-b83e-00224804438a"
          }
        }
      }
    }
  ]
}

Sortie de la console :

Expanded values from Task:
        |Subject                       |Contact                       |Account                  |Account CreatedBy
        |------------------------------|------------------------------|-------------------------|--------------------
        |Task 1 for Susanna Stubberod  |Susanna Stubberod (sample)    |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 2 for Susanna Stubberod  |Susanna Stubberod (sample)    |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 3 for Susanna Stubberod  |Susanna Stubberod (sample)    |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 1 for Nancy Anderson     |Nancy Anderson (sample)       |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 2 for Nancy Anderson     |Nancy Anderson (sample)       |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 3 for Nancy Anderson     |Nancy Anderson (sample)       |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 1 for Maria Cambell      |Maria Cambell (sample)        |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 2 for Maria Cambell      |Maria Cambell (sample)        |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 3 for Maria Cambell      |Maria Cambell (sample)        |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 1 for Scott Konersmann   |Scott Konersmann (sample)     |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 2 for Scott Konersmann   |Scott Konersmann (sample)     |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 3 for Scott Konersmann   |Scott Konersmann (sample)     |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 1 for Robert Lyon        |Robert Lyon (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 2 for Robert Lyon        |Robert Lyon (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 3 for Robert Lyon        |Robert Lyon (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 1 for Paul Cannon        |Paul Cannon (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 2 for Paul Cannon        |Paul Cannon (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 3 for Paul Cannon        |Paul Cannon (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 1 for Rene Valdes        |Rene Valdes (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 2 for Rene Valdes        |Rene Valdes (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 3 for Rene Valdes        |Rene Valdes (sample)          |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 1 for Jim Glynn          |Jim Glynn (sample)            |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 2 for Jim Glynn          |Jim Glynn (sample)            |Contoso, Ltd. (sample)   |FirstName Lastname
        |Task 3 for Jim Glynn          |Jim Glynn (sample)            |Contoso, Ltd. (sample)   |FirstName Lastname

Section 7 : Agréger les résultats

Pour renvoyer des valeurs agrégées, utilisez l’option $apply. Cet exemple applique average, sum, min et max aux valeurs du revenu annuel.

Demande :

GET [Organization Uri]/api/data/v9.2/accounts(7d716234-9628-ed11-9db1-000d3a320482)/contact_customer_accounts?$apply=aggregate(annualincome with average as average, annualincome with sum as total, annualincome with min as minimum, annualincome with max as maximum) HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "value": [
    {
      "telephone3": null,
      "address1_shippingmethodcode": null,
      "familystatuscode": null,
      "haschildrencode": null,
      "nickname": null,
      "address1_freighttermscode": null,
      "address3_upszone": null,
      "_ownerid_value": null,
      "annualincome_base": null,
      "anniversary": null,
      "address1_upszone": null,
      "fullname": null,
      "merged": null,
      "websiteurl": null,
      "address2_city": null,
      "_slainvokedid_value": null,
      "address1_postofficebox": null,
      "importsequencenumber": null,
      "address3_longitude": null,
      "preferredappointmentdaycode": null,
      "customertypecode": null,
      "utcconversiontimezonecode": null,
      "overriddencreatedon": null,
      "aging90": null,
      "stageid": null,
      "address3_primarycontactname": null,
      "address1_utcoffset": null,
      "address1_latitude": null,
      "home2": null,
      "yomifirstname": null,
      "isbackofficecustomer": null,
      "_masterid_value": null,
      "address3_shippingmethodcode": null,
      "lastonholdtime": null,
      "address2_fax": null,
      "address3_stateorprovince": null,
      "address3_telephone3": null,
      "address3_telephone2": null,
      "address3_telephone1": null,
      "_transactioncurrencyid_value": null,
      "governmentid": null,
      "yomifullname": null,
      "participatesinworkflow": null,
      "address2_line1": null,
      "followemail": null,
      "address1_telephone3": null,
      "educationcode": null,
      "address1_telephone2": null,
      "address1_telephone1": null,
      "address2_postofficebox": null,
      "_owninguser_value": null,
      "emailaddress1": null,
      "ftpsiteurl": null,
      "emailaddress2": null,
      "address2_latitude": null,
      "processid": null,
      "emailaddress3": null,
      "address2_shippingmethodcode": null,
      "address2_composite": null,
      "creditonhold": null,
      "traversedpath": null,
      "address1_city": null,
      "spousesname": null,
      "address3_addressid": null,
      "address3_name": null,
      "address3_postofficebox": null,
      "address2_line2": null,
      "aging30_base": null,
      "address1_addressid": null,
      "address1_addresstypecode": null,
      "donotphone": null,
      "managerphone": null,
      "contactid": null,
      "address2_stateorprovince": null,
      "_createdby_value": null,
      "donotemail": null,
      "address2_postalcode": null,
      "donotsendmm": null,
      "entityimage_url": null,
      "firstname": null,
      "address1_composite": null,
      "leadsourcecode": null,
      "aging60": null,
      "managername": null,
      "_modifiedby_value": null,
      "address3_postalcode": null,
      "marketingonly": null,
      "jobtitle": null,
      "timezoneruleversionnumber": null,
      "address3_utcoffset": null,
      "address2_telephone3": null,
      "address2_telephone2": null,
      "address2_telephone1": null,
      "numberofchildren": null,
      "address1_postalcode": null,
      "address2_upszone": null,
      "_owningteam_value": null,
      "address2_line3": null,
      "timespentbymeonemailandmeetings": null,
      "territorycode": null,
      "department": null,
      "address1_country": null,
      "address2_longitude": null,
      "suffix": null,
      "_modifiedonbehalfby_value": null,
      "creditlimit": null,
      "address1_line2": null,
      "paymenttermscode": null,
      "address1_county": null,
      "donotpostalmail": null,
      "_preferredsystemuserid_value": null,
      "accountrolecode": null,
      "preferredappointmenttimecode": null,
      "assistantname": null,
      "address1_fax": null,
      "_owningbusinessunit_value": null,
      "_parentcustomerid_value": null,
      "_createdonbehalfby_value": null,
      "annualincome": null,
      "_accountid_value": null,
      "modifiedon": null,
      "address2_name": null,
      "creditlimit_base": null,
      "_modifiedbyexternalparty_value": null,
      "address2_utcoffset": null,
      "business2": null,
      "statuscode": null,
      "address3_composite": null,
      "_slaid_value": null,
      "fax": null,
      "address1_line1": null,
      "shippingmethodcode": null,
      "donotbulkemail": null,
      "childrensnames": null,
      "address2_county": null,
      "lastname": null,
      "versionnumber": null,
      "address3_city": null,
      "address2_freighttermscode": null,
      "aging30": null,
      "externaluseridentifier": null,
      "address1_line3": null,
      "_parentcontactid_value": null,
      "assistantphone": null,
      "statecode": null,
      "address1_stateorprovince": null,
      "birthdate": null,
      "customersizecode": null,
      "address3_addresstypecode": null,
      "onholdtime": null,
      "_createdbyexternalparty_value": null,
      "entityimage_timestamp": null,
      "mobilephone": null,
      "address3_county": null,
      "employeeid": null,
      "exchangerate": null,
      "subscriptionid": null,
      "entityimageid": null,
      "company": null,
      "donotbulkpostalmail": null,
      "gendercode": null,
      "callback": null,
      "lastusedincampaign": null,
      "address3_line3": null,
      "donotfax": null,
      "telephone2": null,
      "address3_freighttermscode": null,
      "yomilastname": null,
      "address3_fax": null,
      "description": null,
      "address3_line1": null,
      "address3_line2": null,
      "address2_addresstypecode": null,
      "createdon": null,
      "yomimiddlename": null,
      "aging90_base": null,
      "address1_name": null,
      "telephone1": null,
      "address1_primarycontactname": null,
      "address1_longitude": null,
      "middlename": null,
      "address2_primarycontactname": null,
      "entityimage": null,
      "address2_addressid": null,
      "preferredcontactmethodcode": null,
      "address3_latitude": null,
      "salutation": null,
      "aging60_base": null,
      "pager": null,
      "address2_country": null,
      "address3_country": null,
      "average@OData.Community.Display.V1.AttributeName": "annualincome",
      "average@OData.Community.Display.V1.FormattedValue": "$61,300.00",
      "average": 61300.0,
      "total@OData.Community.Display.V1.AttributeName": "annualincome",
      "total@OData.Community.Display.V1.FormattedValue": "$490,400.00",
      "total": 490400.0,
      "minimum@OData.Community.Display.V1.AttributeName": "annualincome",
      "minimum@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "minimum": 31000.0,
      "maximum@OData.Community.Display.V1.AttributeName": "annualincome",
      "maximum@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "maximum": 86000.0
    }
  ]
}

Sortie de la console :

Aggregated Annual Income information for Contoso contacts:
        Average income: $61,300.00
        Total income: $490,400.00
        Minium income: $31,000.00
        Maximum income: $86,000.00

Section 8 : FetchXML requêtes

Outre les opérations de filtrage des requêtes, l’API Web prend également en charge FetchXML requêtes. FetchXML fournit une manière alternative de définir des requêtes et davantage d’options d’agrégation. Toutes les options de requête que nous définirions normalement comme $select, $filter, et $orderby sont définies dans le code XML.

Utiliser FetchXML, composez une chaîne qui représente la requête. Assurez-vous que la chaîne de requête est conforme à la référence FetchXml. Avant d’inclure la chaîne dans l’URL, vous devez l’encoder en URL.

Dans cet exemple, nous interrogeons tous les contacts dont le fullname correspond à (sample), et nous classons les résultats par ordre décroissant selon le fullname.

Il s’agit du XML de la requête :

<fetch mapping="logical" output-format="xml-platform" version="1.0" distinct="false">  
  <entity name="contact">  
    <attribute name="fullname" />  
    <attribute name="jobtitle" />  
    <attribute name="annualincome" />  
    <order descending="true"  
           attribute="fullname" />  
    <filter type="and">  
      <condition value="%(sample)%"  
                 attribute="fullname"  
                 operator="like" />
      <condition value="7d716234-9628-ed11-9db1-000d3a320482"
                 attribute="parentcustomerid"
                 operator="eq" /> 
    </filter>  
  </entity>  
</fetch>  

Dans cet exemple, la requête est envoyée à l’aide d’une requête $batch. FetchXML les requêtes peuvent être longues, elles peuvent donc atteindre les limites des URL pouvant être envoyées à l’aide GET. Avec une opération $batch, l’URL est envoyée dans le corps de la requête, là où les limites sont plus élevées.

Demande :

POST [Organization Uri]/api/data/v9.2/$batch HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

--batch_7118cb08-27c1-44c0-be91-c2442fe9d454
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 881

GET /api/data/v9.2/contacts?fetchXml=%3Cfetch+mapping%3D%22logical%22+output-format%3D%22xml-platform%22+version%3D%221.0%22+distinct%3D%22false%22%3E%0D%0A++%3Centity+name%3D%22contact%22%3E%0D%0A++++%3Cattribute+name%3D%22fullname%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22jobtitle%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22annualincome%22+%2F%3E%0D%0A++++%3Corder+descending%3D%22true%22+attribute%3D%22fullname%22+%2F%3E%0D%0A++++%3Cfilter+type%3D%22and%22%3E%0D%0A++++++%3Ccondition+value%3D%22%25(sample)%25%22+attribute%3D%22fullname%22+operator%3D%22like%22+%2F%3E%0D%0A++++++%3Ccondition+value%3D%227d716234-9628-ed11-9db1-000d3a320482%22+attribute%3D%22parentcustomerid%22+operator%3D%22eq%22+%2F%3E%0D%0A++++%3C%2Ffilter%3E%0D%0A++%3C%2Fentity%3E%0D%0A%3C%2Ffetch%3E&$count=true HTTP/1.1
Prefer: odata.include-annotations="*"


--batch_7118cb08-27c1-44c0-be91-c2442fe9d454--

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0

--batchresponse_ed1a482b-c942-4da4-8257-adaa53acc8e0
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome,_transactioncurrencyid_value,transactioncurrencyid,contactid,transactioncurrencyid())",
  "@odata.count": 8,
  "@Microsoft.Dynamics.CRM.totalrecordcount": 8,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1146759\"",
      "fullname": "Susanna Stubberod (sample)",
      "jobtitle": "Senior Purchaser",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$52,000.00",
      "annualincome": 52000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "85716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146765\"",
      "fullname": "Scott Konersmann (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$38,000.00",
      "annualincome": 38000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "91716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146767\"",
      "fullname": "Robert Lyon (sample)",
      "jobtitle": "Senior Technician",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$78,000.00",
      "annualincome": 78000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "95716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146771\"",
      "fullname": "Rene Valdes (sample)",
      "jobtitle": "Data Analyst III",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$86,000.00",
      "annualincome": 86000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "9d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146769\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146761\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146763\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1146773\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}
--batchresponse_ed1a482b-c942-4da4-8257-adaa53acc8e0--

Sortie de la console :

Contacts Fetched by fullname containing '(sample)':
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Susanna Stubberod (sample) |Senior Purchaser                   |$52,000.00
        |Scott Konersmann (sample)  |Accounts Manager                   |$38,000.00
        |Robert Lyon (sample)       |Senior Technician                  |$78,000.00
        |Rene Valdes (sample)       |Data Analyst III                   |$86,000.00
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

FetchXML pagination

Le chemin FetchXML la gestion de la pagination est différente de la façon dont un filtre de requête la gère. Dans FetchXML, vous pouvez spécifier un count colonne qui indique combien de résultats renvoyer par page. Dans la même demande, vous utilisez la colonne page pour spécifier le numéro de page à renvoyer.

L’opération suivante demande la page 2 de la précédente FetchXML échantillon. Selon nos exemples de données, nous devons avoir huit contacts dans notre résultat. En décomposant chaque page à seulement quatre contacts par page, nous devrions avoir deux pages. La page 2 ne doit contenir que quatre contacts. Si nous demandons ensuite la page 3, le système renvoie zéro résultat.

<fetch mapping="logical" 
        output-format="xml-platform" 
        version="1.0" 
        distinct="false"
        page="2"  
        count="4">  
  <entity name="contact">  
    <attribute name="fullname" />  
    <attribute name="jobtitle" />  
    <attribute name="annualincome" />  
    <order descending="true"  
           attribute="fullname" />  
    <filter type="and">  
      <condition value="%(sample)%"  
                 attribute="fullname"  
                 operator="like" />
      <condition value="7d716234-9628-ed11-9db1-000d3a320482"
                 attribute="parentcustomerid"
                 operator="eq" /> 
    </filter>  
  </entity>  
</fetch>  

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?fetchXml=%3Cfetch+mapping%3D%22logical%22+output-format%3D%22xml-platform%22+version%3D%221.0%22+distinct%3D%22false%22+count%3D%224%22+page%3D%222%22%3E%0D%0A++%3Centity+name%3D%22contact%22%3E%0D%0A++++%3Cattribute+name%3D%22fullname%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22jobtitle%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22annualincome%22+%2F%3E%0D%0A++++%3Corder+descending%3D%22true%22+attribute%3D%22fullname%22+%2F%3E%0D%0A++++%3Cfilter+type%3D%22and%22%3E%0D%0A++++++%3Ccondition+value%3D%22%25(sample)%25%22+attribute%3D%22fullname%22+operator%3D%22like%22+%2F%3E%0D%0A++++++%3Ccondition+value%3D%227d716234-9628-ed11-9db1-000d3a320482%22+attribute%3D%22parentcustomerid%22+operator%3D%22eq%22+%2F%3E%0D%0A++++%3C%2Ffilter%3E%0D%0A++%3C%2Fentity%3E%0D%0A%3C%2Ffetch%3E&$count=true HTTP/1.1
Prefer: odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,jobtitle,annualincome,_transactioncurrencyid_value,transactioncurrencyid,contactid,transactioncurrencyid())",
  "@odata.count": 8,
  "@Microsoft.Dynamics.CRM.totalrecordcount": 8,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1147963\"",
      "fullname": "Paul Cannon (sample)",
      "jobtitle": "Ski Instructor",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$68,500.00",
      "annualincome": 68500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "99716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1147945\"",
      "fullname": "Nancy Anderson (sample)",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "89716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1147948\"",
      "fullname": "Maria Cambell (sample)",
      "jobtitle": "Accounts Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$31,000.00",
      "annualincome": 31000.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "8d716234-9628-ed11-9db1-000d3a320482"
    },
    {
      "@odata.etag": "W/\"1147979\"",
      "fullname": "Jim Glynn (sample)",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac",
      "contactid": "a1716234-9628-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

Contacts Fetched by fullname containing '(sample)' - Page 2:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Paul Cannon (sample)       |Ski Instructor                     |$68,500.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00
        |Maria Cambell (sample)     |Accounts Manager                   |$31,000.00
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00

Section 9 : Utilisation des requêtes prédéfinies

Vous pouvez utiliser l’API Web pour récupérer et exécuter des requêtes prédéfinies.

Requête enregistrée

Dans cette opération, nous faisons une demande de GUID savedqueryid de la requête enregistrée nommée Comptes actifs. Puis avec le GUID et le paramètre savedQuery, nous lançons une requête pour une liste de comptes actifs.

Tout d’abord, nous obtenons le GUID de la requête enregistrée.

Demande :

GET [Organization Uri]/api/data/v9.2/savedqueries?$select=name,savedqueryid&$filter=name eq 'Active Accounts' HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#savedqueries(name,savedqueryid)",
  "value": [
    {
      "@odata.etag": "W/\"966435\"",
      "name": "Active Accounts",
      "savedqueryid": "00000000-0000-0000-00aa-000010001002"
    }
  ]
}

Ensuite, nous utilisons le paramètre savedQuery pour obtenir le contenu de la requête enregistrée.

Demande :

GET [Organization Uri]/api/data/v9.2/accounts?savedQuery=00000000-0000-0000-00aa-000010001002 HTTP/1.1
Prefer: odata.maxpagesize=3; odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"; odata.maxpagesize=3

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#accounts(name,_primarycontactid_value,primarycontactid,accountid,address1_city,telephone1,primarycontactid())",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "@accountprimarycontactidcontactcontactid.OData.Community.Display.V1.CurrentEntityField": "primarycontactid",
  "value": [
    {
      "@odata.etag": "W/\"1147935\"",
      "name": "Contoso, Ltd. (sample)",
      "_primarycontactid_value@OData.Community.Display.V1.FormattedValue": "Yvonne McKay (sample)",
      "_primarycontactid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "primarycontactid",
      "_primarycontactid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "contact",
      "_primarycontactid_value": "d36e86e2-a228-ed11-9db1-000d3a320482",
      "accountid": "cf6e86e2-a228-ed11-9db1-000d3a320482"
    }
  ]
}

Sortie de la console :

-- Saved Query --

Active Accounts
        1) Contoso, Ltd. (sample), Yvonne McKay (sample), NULL

Requête utilisateur

Cet exemple crée une requête utilisateur, l’exécute, puis la supprime du système.

Demande :

POST [Organization Uri]/api/data/v9.2/userqueries HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

{
  "name": "My User Query",
  "description": "User query to display contact info.",
  "querytype": 0,
  "returnedtypecode": "contact",
  "fetchxml": "<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false'>
    <entity name ='contact'>
      <attribute name ='fullname' />
      <attribute name ='contactid' />
      <attribute name ='jobtitle' />
      <attribute name ='annualincome' />
      <order descending ='false' attribute='fullname' />
      <filter type ='and'>
         <condition value ='%(sample)%' attribute='fullname' operator='like' />
         <condition value ='%Manager%' attribute='jobtitle' operator='like' />
         <condition value ='55000' attribute='annualincome' operator='gt' />
      </filter>
    </entity>
</fetch>"
}

Réponse :

HTTP/1.1 204 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/userqueries(f76e86e2-a228-ed11-9db1-000d3a320482)

Cette requête utilisateur demande tous les contacts dont fullname contient (sample), jobtitle contient manager, et annualincome supérieur à 55000. Nos exemples de données ont deux contacts correspondant à la requête.

Dans l’exemple de code, la valeur userqueryid est renvoyée avec la requête qui la crée. Normalement, vous devez interroger le système pour le récupérer à l’aide d’une requête comme celle-ci :

Demande :

GET https://[Organization URI]/api/data/v9.2/userqueries?$select=name,userqueryid,&$filter=name%20eq%20'My%20User%20Query' HTTP/1.1  
OData-MaxVersion: 4.0  
OData-Version: 4.0  
Content-Type: application/json; charset=utf-8  
  

Réponse :

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal  
OData-Version: 4.0  
Content-Length: 246  
  
{   
   "@odata.context":"https://[Organization URI]/api/data/v9.2/$metadata#userqueries(name,userqueryid)",  
   "value":[   
      {   
         "@odata.etag":"W/\"621698\"",  
         "name":"My User Query",  
         "userqueryid":"f76e86e2-a228-ed11-9db1-000d3a320482"  
      }  
   ]  
}  

Cet exemple transmet la valeur GUID au paramètre userQuery pour obtenir le contenu de la requête de l’utilisateur.

Demande :

GET [Organization Uri]/api/data/v9.2/contacts?userQuery=f76e86e2-a228-ed11-9db1-000d3a320482 HTTP/1.1
Prefer: odata.maxpagesize=3; odata.include-annotations="*"
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"; odata.maxpagesize=3

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#contacts(fullname,contactid,jobtitle,annualincome,_transactioncurrencyid_value,transactioncurrencyid,transactioncurrencyid())",
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "1144249",
  "value": [
    {
      "@odata.etag": "W/\"1147979\"",
      "fullname": "Jim Glynn (sample)",
      "contactid": "f36e86e2-a228-ed11-9db1-000d3a320482",
      "jobtitle": "Senior International Sales Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$81,400.00",
      "annualincome": 81400.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac"
    },
    {
      "@odata.etag": "W/\"1147945\"",
      "fullname": "Nancy Anderson (sample)",
      "contactid": "db6e86e2-a228-ed11-9db1-000d3a320482",
      "jobtitle": "Activities Manager",
      "annualincome@OData.Community.Display.V1.FormattedValue": "$55,500.00",
      "annualincome": 55500.0,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue": "US Dollar",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "transactioncurrencyid",
      "_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "transactioncurrency",
      "_transactioncurrencyid_value": "daf76074-6820-ed11-b83b-00224802b2ac"
    }
  ]
}

Sortie de la console :

-- User Query --

Contacts Fetched by My User Query:
        |Full Name                  |Job Title                          |Annual Income
        |---------------------------|-----------------------------------|---------------
        |Jim Glynn (sample)         |Senior International Sales Manager |$81,400.00
        |Nancy Anderson (sample)    |Activities Manager                 |$55,500.00

Section 10 : Supprimer des exemples d’enregistrements

Utiliser une opération $batch pour supprimer tous les enregistrements créés dans Section 0 : Créer des enregistrements à interroger.

Demande :

POST [Organization Uri]/api/data/v9.2/$batch HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(f36e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(ef6e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(eb6e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(e76e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(e36e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(df6e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(db6e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(d76e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/accounts(cf6e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121

DELETE /api/data/v9.2/contacts(d36e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 124

DELETE /api/data/v9.2/userqueries(f76e86e2-a228-ed11-9db1-000d3a320482) HTTP/1.1


--batch_23ea682f-a60a-412a-b37d-7df10a976508--

Réponse :

HTTP/1.1 200 OK
OData-Version: 4.0

--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
OData-Version: 4.0


--batchresponse_1e45a745-8b68-401f-a1c0-0081ec083cdc--

Voir aussi

Utiliser l’API Web Dataverse
Interroger des données à l’aide de l’API Web
Extraire et exécuter des requêtes prédéfinies
Exemples de données de requête d’API web (C#)
Exemple de données de requête de l’API Web (Javascript côté client)

Notes

Pouvez-vous nous indiquer vos préférences de langue pour la documentation ? Répondez à un court questionnaire. (veuillez noter que ce questionnaire est en anglais)

Le questionnaire vous prendra environ sept minutes. Aucune donnée personnelle n’est collectée (déclaration de confidentialité).