Partager via


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

 

Date de publication : janvier 2017

S’applique à : Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

Ce groupe d'exemples montre comment interroger des données à l'aide de l'API Web Microsoft Dynamics 365. 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)

Sélection des propriétés spécifiques

Récupérer des propriétés spécifiques

Inclure des valeurs mises en forme

Utilisation des fonctions de requête

Filtrer les résultats

Fonctionnalités de requête standard

Composer une requête avec des fonctions

Web API Query Function Reference

Utilisation d'opérateurs

Opérateurs de filtre standard

Priorité des paramètres

Opérateurs de filtre standard

Classement des résultats

Classer les résultats

Filtrer les résultats

Alias de paramètre

Utiliser des alias de paramètre avec des options de requête système

Limiter les résultats

Limiter les résultats

Limite le nombre d'entités renvoyées

Développement des résultats

Extraire les entités associées en développant les propriétés de navigation

Requêtes FetchXML

FetchXML schema

Mettre en page d’importants ensembles de résultats avec FetchXML

Utiliser la requête FetchXML personnalisée

Requêtes prédéfinies

Extraire et exécuter des requêtes prédéfinies

userquery EntityType

savedquery EntityType

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

Exemple de données

Pour vous assurer que les requêtes de cet exemple de travail fonctionnent correctement, un ensemble standard d'exemples d'enregistrements est créé par cet exemple. Ces exemples d'enregistrements sont supprimés sauf si l'utilisateur choisit de ne pas les supprimer. Il s'agit de des données que l'exemple interrogera. 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)",
           "primarycontactid": {
               "firstname": "Yvonne", "lastname": "McKay (sample)", "jobtitle": "Coffee Master",
               "annualincome": 45000, "Contact_Tasks": [
               { "subject": "Task 1", "description": "Task 1 description" },
               { "subject": "Task 2", "description": "Task 2 description" },
               { "subject": "Task 3", "description": "Task 3 description" }
               ]
           }, 
                            "Account_Tasks": [
           { "subject": "Task 1", "description": "Task 1 description" },
           { "subject": "Task 2", "description": "Task 2 description" },
           { "subject": "Task 3", "description": "Task 3 description" }
           ],
           "contact_customer_accounts": [
               {
                   "firstname": "Susanna", "lastname": "Stubberod (sample)", "jobtitle": "Senior Purchaser",
                   "annualincome": 52000, "Contact_Tasks": [
               { "subject": "Task 1", "description": "Task 1 description" },
               { "subject": "Task 2", "description": "Task 2 description" },
               { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               },
               {
                   "firstname": "Nancy", "lastname": "Anderson (sample)", "jobtitle": "Activities Manager",
                   "annualincome": 55500, "Contact_Tasks": [
                   { "subject": "Task 1", "description": "Task 1 description" },
                   { "subject": "Task 2", "description": "Task 2 description" },
                   { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               },
               {
                   "firstname": "Maria", "lastname": "Cambell (sample)", "jobtitle": "Accounts Manager",
                   "annualincome": 31000, "Contact_Tasks": [
                   { "subject": "Task 1", "description": "Task 1 description" },
                   { "subject": "Task 2", "description": "Task 2 description" },
                   { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               },
               {
                   "firstname": "Nancy", "lastname": "Anderson (sample)", "jobtitle": "Logistics Specialist",
                   "annualincome": 63500, "Contact_Tasks": [
                   { "subject": "Task 1", "description": "Task 1 description" },
                   { "subject": "Task 2", "description": "Task 2 description" },
                   { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               },
               {
                   "firstname": "Scott", "lastname": "Konersmann (sample)", "jobtitle": "Accounts Manager",
                   "annualincome": 38000, "Contact_Tasks": [
                   { "subject": "Task 1", "description": "Task 1 description" },
                   { "subject": "Task 2", "description": "Task 2 description" },
                   { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               },
               {
                   "firstname": "Robert", "lastname": "Lyon (sample)", "jobtitle": "Senior Technician",
                   "annualincome": 78000, "Contact_Tasks": [
                   { "subject": "Task 1", "description": "Task 1 description" },
                   { "subject": "Task 2", "description": "Task 2 description" },
                   { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               },
               {
                   "firstname": "Paul", "lastname": "Cannon (sample)", "jobtitle": "Ski Instructor",
                   "annualincome": 68500, "Contact_Tasks": [
                   { "subject": "Task 1", "description": "Task 1 description" },
                   { "subject": "Task 2", "description": "Task 2 description" },
                   { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               },
               {
                   "firstname": "Rene", "lastname": "Valdes (sample)", "jobtitle": "Data Analyst III",
                   "annualincome": 86000, "Contact_Tasks": [
                   { "subject": "Task 1", "description": "Task 1 description" },
                   { "subject": "Task 2", "description": "Task 2 description" },
                   { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               },
               {
                   "firstname": "Jim", "lastname": "Glynn (sample)", "jobtitle": "Senior International Sales Manager",
                   "annualincome": 81400, "Contact_Tasks": [
                   { "subject": "Task 1", "description": "Task 1 description" },
                   { "subject": "Task 2", "description": "Task 2 description" },
                   { "subject": "Task 3", "description": "Task 3 description" }
                   ]
               }
           ]
       }

Sélection des propriétés spécifiques

Construisez toujours les requêtes à l'aide de l'option de requête $select, sinon le serveur renverra toutes les propriétés de chaque entité, ce qui réduit les performances. 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 présente également les différences entre les valeurs mises en forme et non mises en forme comme dans les résultats de la propriété annualincome du contact.Pour plus d'informations :Propriétés spécifiques de la demande, Inclure des valeurs mises en forme.

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

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts(b848fdee-c143-e611-80d5-00155da84802)?$select=fullname,jobtitle,annualincome HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 517

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)/$entity",
   "@odata.etag":"W/\"619718\"",
   "fullname":"Yvonne McKay (sample)",
   "jobtitle":"Coffee Master",
   "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
   "annualincome":45000.0000,
   "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
   "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
   "contactid":"15c364b2-bf43-e611-80d5-00155da84802"
}

Sortie de la console

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

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.Pour plus d'informations :Filtrer les résultats.

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

Fonctionnalités de requête standard

Dynamics 365 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. Dans cette opération, nous interrogeons l'ensemble des contacts dont fullname contenant la chaîne (sample).Pour plus d'informations :Fonctionnalités de requête standard.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)') HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 4284

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "value":[
      {
         "@odata.etag":"W/\"619718\"",
         "fullname":"Yvonne McKay (sample)",
         "jobtitle":"Coffee Master",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
         "annualincome":45000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"15c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619839\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"1cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619841\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"20c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619843\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"24c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619845\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"28c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619847\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"2cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619849\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"30c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619851\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"34c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619853\"",
         "fullname":"Rene Valdes (sample)",
         "jobtitle":"Data Analyst III",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$86,000.00",
         "annualincome":86000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"38c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619855\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"3cc364b2-bf43-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts filtered by fullname containing '(sample)':
    1) Yvonne McKay (sample), Coffee Master, $45,000.00
    2) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    3) Nancy Anderson (sample), Activities Manager, $55,500.00
    4) Maria Cambell (sample), Accounts Manager, $31,000.00
    5) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    6) Scott Konersmann (sample), Accounts Manager, $38,000.00
    7) Robert Lyon (sample), Senior Technician, $78,000.00
    8) Paul Cannon (sample), Ski Instructor, $68,500.00
    9) Rene Valdes (sample), Data Analyst III, $86,000.00
    10) Jim Glynn (sample), Senior International Sales Manager, $81,400.00

Fonctions de requête Dynamics 365

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

Vous utiliserez ces fonctions de requête d'une manière semblable aux fonctions standard de requête. La principale différence est, lorsque vous utilisez des fonctions de requête Dynamics 365, 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 LastXHours Function.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=Microsoft.Dynamics.CRM.LastXHours(PropertyName='createdon',PropertyValue='1') HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 4284

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "value":[
      {
         "@odata.etag":"W/\"619718\"",
         "fullname":"Yvonne McKay (sample)",
         "jobtitle":"Coffee Master",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
         "annualincome":45000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"15c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619839\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"1cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619841\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"20c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619843\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"24c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619845\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"28c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619847\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"2cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619849\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"30c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619851\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"34c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619853\"",
         "fullname":"Rene Valdes (sample)",
         "jobtitle":"Data Analyst III",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$86,000.00",
         "annualincome":86000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"38c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619855\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"3cc364b2-bf43-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts that were created within the last 1hr:
    1) Yvonne McKay (sample), Coffee Master, $45,000.00
    2) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    3) Nancy Anderson (sample), Activities Manager, $55,500.00
    4) Maria Cambell (sample), Accounts Manager, $31,000.00
    5) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    6) Scott Konersmann (sample), Accounts Manager, $38,000.00
    7) Robert Lyon (sample), Senior Technician, $78,000.00
    8) Paul Cannon (sample), Ski Instructor, $68,500.00
    9) Rene Valdes (sample), Data Analyst III, $86,000.00
    10) Jim Glynn (sample), Senior International Sales Manager, $81,400.00

Utilisation d'opérateurs

Utilisez Opérateurs de filtre standard (eq,ne,gt,ge,lt,le,and,or,not) pour affiner davantage les 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 HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')%20and%20annualincome%20gt%2055000 HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 2629

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "value":[
      {
         "@odata.etag":"W/\"619841\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"20c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619845\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"28c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619849\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"30c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619851\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"34c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619853\"",
         "fullname":"Rene Valdes (sample)",
         "jobtitle":"Data Analyst III",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$86,000.00",
         "annualincome":86000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"38c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619855\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"3cc364b2-bf43-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts filtered by fullname and annualincome (<$55,000):
    1) Nancy Anderson (sample), Activities Manager, $55,500.00
    2) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    3) Robert Lyon (sample), Senior Technician, $78,000.00
    4) Paul Cannon (sample), Ski Instructor, $68,500.00
    5) Rene Valdes (sample), Data Analyst III, $86,000.00
    6) Jim Glynn (sample), Senior International Sales Manager, $81,400.00

Priorité des paramètres

Vous utilisez des crochets pour établir l'ordre dans lequel les conditions sont évaluées.

Dans cet exemple, nous interrogeons la liste de tous les contacts avec fullname contenant (sample), jobtitle contenant senior ou specialist 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. Étant donné que tous les opérateurs disposent de la même priorité, le fait d'omettre les crochets offre à l'opérateur or la même priorité que les opérateurs and. Les filtres sont appliqués de gauche à droite. La commande dans laquelle ces instructions s'affichent dans le filtre peut affecter les résultats. Voici à quoi la requête de cet exemple ressemble : $filter=contains(fullname,'(sample)') and (contains(jobtitle,'senior') or contains(jobtitle,'specialist')) and annualincome gt 55000.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')%20and%20(contains(jobtitle,'senior')%20or%20contains(jobtitle,'specialist'))%20and%20annualincome%20gt%2055000 HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 1393

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "value":[
      {
         "@odata.etag":"W/\"619845\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"28c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619849\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"30c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619855\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"3cc364b2-bf43-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts filtered by fullname, annualincome and jobtitle (Senior or Specialist):
    1) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    2) Robert Lyon (sample), Senior Technician, $78,000.00
    3) Jim Glynn (sample), Senior International Sales Manager, $81,400.00

Classement des résultats

Vous pouvez spécifier un ordre croissant ou décroissant sur les résultats à l'aide de 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.Pour plus d'informations :Classer les résultats.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')%20&$orderby=jobtitle%20asc,%20annualincome%20desc HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 4284

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "value":[
      {
         "@odata.etag":"W/\"619847\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"2cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619843\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"24c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619841\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"20c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619718\"",
         "fullname":"Yvonne McKay (sample)",
         "jobtitle":"Coffee Master",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
         "annualincome":45000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"15c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619853\"",
         "fullname":"Rene Valdes (sample)",
         "jobtitle":"Data Analyst III",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$86,000.00",
         "annualincome":86000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"38c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619845\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"28c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619855\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"3cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619839\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"1cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619849\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"30c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619851\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"34c364b2-bf43-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts ordered by jobtitle (ascending) and annualincome (descending):
    1) Scott Konersmann (sample), Accounts Manager, $38,000.00
    2) Maria Cambell (sample), Accounts Manager, $31,000.00
    3) Nancy Anderson (sample), Activities Manager, $55,500.00
    4) Yvonne McKay (sample), Coffee Master, $45,000.00
    5) Rene Valdes (sample), Data Analyst III, $86,000.00
    6) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    7) Jim Glynn (sample), Senior International Sales Manager, $81,400.00
    8) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    9) Robert Lyon (sample), Senior Technician, $78,000.00
    10) Paul Cannon (sample), Ski Instructor, $68,500.00

Alias de paramètre

Utilisez les alias de paramètres pour réutiliser plus facilement les paramètres dans vos filtres. Les alias paramétrés peuvent être utilisés 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.Pour plus d'informations :Utiliser des fonctions API Web, Utiliser des alias de paramètre avec des options de requête système. Prenons l'opération des résultats de commande par exemple, nous allons entrer cette requête de nouveau en utilisant les paramètres et nous obtiendrons les mêmes résultats de sortie.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(@p1,'(sample)')%20&$orderby=@p2%20asc,%20@p3%20desc&@p1=fullname&@p2=jobtitle&@p3=annualincome HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 4284

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "value":[
      {
         "@odata.etag":"W/\"619847\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"2cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619843\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"24c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619841\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"20c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619718\"",
         "fullname":"Yvonne McKay (sample)",
         "jobtitle":"Coffee Master",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
         "annualincome":45000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"15c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619853\"",
         "fullname":"Rene Valdes (sample)",
         "jobtitle":"Data Analyst III",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$86,000.00",
         "annualincome":86000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"38c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619845\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"28c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619855\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"3cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619839\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"1cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619849\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"30c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619851\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"34c364b2-bf43-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts list using parameterized aliases:
    1) Scott Konersmann (sample), Accounts Manager, $38,000.00
    2) Maria Cambell (sample), Accounts Manager, $31,000.00
    3) Nancy Anderson (sample), Activities Manager, $55,500.00
    4) Yvonne McKay (sample), Coffee Master, $45,000.00
    5) Rene Valdes (sample), Data Analyst III, $86,000.00
    6) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    7) Jim Glynn (sample), Senior International Sales Manager, $81,400.00
    8) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    9) Robert Lyon (sample), Senior Technician, $78,000.00
    10) Paul Cannon (sample), Ski Instructor, $68,500.00

Limiter les résultats

Renvoyer plus de données que nécessaire est néfaste pour vos performances. Le serveur renverra un maximum de 5 000 entités par demande. Vous pouvez limiter le nombre de résultats renvoyés à l'aide de l'option de requête $top ou en ajoutant odata.maxpagesize dans l'en-tête de requête. L'option de requête $top renvoie uniquement le nombre supérieur d'entités du résultat défini et ignore le reste. L'en-tête de demande odata.maxpagesize spécifie le nombre d'entités renvoyées par page avec une propriété @odata.nextLink** pour obtenir des résultats de la page suivante. Pour plus d'informations sur **odata.maxpagesize, voir la section sur Pagination, ainsi que Limite le nombre d'entités renvoyées.

Résultats principaux

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 HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')&$top=5 HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Content-Length: 2209

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "value":[
      {
         "@odata.etag":"W/\"619718\"",
         "fullname":"Yvonne McKay (sample)",
         "jobtitle":"Coffee Master",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
         "annualincome":45000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"15c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619839\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"1cc364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619841\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"20c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619843\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"24c364b2-bf43-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"619845\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"28c364b2-bf43-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts top 5 results:
    1) Yvonne McKay (sample), Coffee Master, $45,000.00
    2) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    3) Nancy Anderson (sample), Activities Manager, $55,500.00
    4) Maria Cambell (sample), Accounts Manager, $31,000.00
    5) Nancy Anderson (sample), Logistics Specialist, $63,500.00

Nombre de résultats

Vous pouvez obtenir facilement le nombre d'enregistrements de propriété avec une valeur de collection ou un nombre d'entités mises en correspondance dans un filtre. L'obtention d'un nombre nous indique le nombre d'entités possibles dans notre résultat. Toutefois, le serveur Dynamics 365 renvoie 5 000 comme nombre maximal, même si le résultat peut être supérieur. Dans cet exemple, nous avons créée 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.Pour plus d'informations :Récupérer un nombre d'entités.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(jobtitle,'senior')%20or%20contains(jobtitle,%20'manager')&$count=true HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 2654

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "@odata.count":6,
   "value":[
      {
         "@odata.etag":"W/\"620258\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"bf48fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620260\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"c348fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620262\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"c748fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620266\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"cf48fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620268\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"d348fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620274\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"df48fdee-c143-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

6 contacts have either 'Manager' or 'Senior' designation in their jobtitle.
Manager or Senior:
    1) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    2) Nancy Anderson (sample), Activities Manager, $55,500.00
    3) Maria Cambell (sample), Accounts Manager, $31,000.00
    4) Scott Konersmann (sample), Accounts Manager, $38,000.00
    5) Robert Lyon (sample), Senior Technician, $78,000.00
    6) Jim Glynn (sample), Senior International Sales Manager, $81,400.00

Pagination

Pour récupérer un sous-ensemble séquentiel des résultats d'une requête qui renvoie un grand nombre d'entités, utilisez odata.maxpagesize au lieu de $top.Pour plus d'informations :Spécifiez le nombre d'entités à renvoyer dans une page.

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 HTTP

GET http://cc_WebAPI_ServiceURI/contacts?$select=fullname,jobtitle,annualincome&$filter=contains(fullname,'(sample)')&$count=true HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=4, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=4
Content-Length: 2294

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "@odata.count":10,
   "value":[
      {
         "@odata.etag":"W/\"620138\"",
         "fullname":"Yvonne McKay (sample)",
         "jobtitle":"Coffee Master",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
         "annualincome":45000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"b848fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620258\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"bf48fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620260\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"c348fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620262\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"c748fdee-c143-e611-80d5-00155da84802"
      }
   ],
   "@odata.nextLink":"http://cc_WebAPI_ServiceURI/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%257bC748FDEE-C143-E611-80D5-00155DA84802%257d%2522%2520first%253d%2522%257bB848FDEE-C143-E611-80D5-00155DA84802%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E"
}

Sortie de la console

Contacts total: 10     Contacts per page: 4.
Page 1 of 3:
    1) Yvonne McKay (sample), Coffee Master, $45,000.00
    2) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    3) Nancy Anderson (sample), Activities Manager, $55,500.00
    4) 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 HTTP

GET http://cc_WebAPI_ServiceURI/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%257bC748FDEE-C143-E611-80D5-00155DA84802%257d%2522%2520first%253d%2522%257bB848FDEE-C143-E611-80D5-00155DA84802%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=4, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=4
Content-Length: 2294

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome)",
   "@odata.count":10,
   "value":[
      {
         "@odata.etag":"W/\"620264\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"cb48fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620266\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"cf48fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620268\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"d348fdee-c143-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620270\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"d748fdee-c143-e611-80d5-00155da84802"
      }
   ],
   "@odata.nextLink":"http://cc_WebAPI_ServiceURI/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%257bD748FDEE-C143-E611-80D5-00155DA84802%257d%2522%2520first%253d%2522%257bCB48FDEE-C143-E611-80D5-00155DA84802%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E"
}

Sortie de la console

Page 2 of 3:
    1) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    2) Scott Konersmann (sample), Accounts Manager, $38,000.00
    3) Robert Lyon (sample), Senior Technician, $78,000.00
    4) Paul Cannon (sample), Ski Instructor, $68,500.00

Développement des résultats

Pour récupérer les informations sur les entités associées, utilisez l'option de requête $expand sur les propriétés de navigation.Pour plus d'informations :Extraire les entités associées en développant les propriétés de navigation.

Développez 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 l'attribut primarycontactid. Dans cette relation, le compte peut posséder un contact principal. À l'aide de account 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 HTTP

GET http://cc_WebAPI_ServiceURI/accounts(b2546951-c543-e611-80d5-00155da84802)?$select=name&$expand=primarycontactid($select=fullname,jobtitle,annualincome) HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 700

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#accounts(name,primarycontactid,primarycontactid(fullname,jobtitle,annualincome))/$entity",
   "@odata.etag":"W/\"620641\"",
   "name":"Contoso, Ltd. (sample)",
   "accountid":"b2546951-c543-e611-80d5-00155da84802",
   "primarycontactid":{
      "@odata.etag":"W/\"620534\"",
      "fullname":"Yvonne McKay (sample)",
      "jobtitle":"Coffee Master",
      "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
      "annualincome":45000.0000,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
      "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
      "contactid":"b3546951-c543-e611-80d5-00155da84802"
   }
}

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. Les attribut que vous utilisez dépendent de l'entité de base sur laquelle s'appuie la requête. Par exemple, dans l'opération précédente, nous avons créé une requête sur account EntityType et nous souhaitions obtenir des informations supplémentaires sur son contact principal. Nous avons procédé via l'attribut primarycontactid. Si nous recherchons le account EntityType, sous la section Single-valued navigation properties, nous voyons que la propriété partenaire qui correspond à primarycontactid est la propriété de navigation avec une valeur de collection account_primary_contact trouvée sur le contact EntityType.

En écrivant une requête sur un contact, vous pouvez développer sur l'attribut account_primary_contact pour obtenir des informations sur les comptes où 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, elle peut éventuellement être attribuée à d'autres comptes comme contact principal. Du fait que la propriété account_primary_contact a une relation plusieurs-à-un le résultat est renvoyé sous la forme d'un tableau d'entités de compte.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts(b3546951-c543-e611-80d5-00155da84802)?$select=fullname,jobtitle,annualincome&$expand=account_primary_contact($select=name) HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 737

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome,account_primary_contact,account_primary_contact(name))/$entity",
   "@odata.etag":"W/\"620534\"",
   "fullname":"Yvonne McKay (sample)",
   "jobtitle":"Coffee Master",
   "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
   "annualincome":45000.0000,
   "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
   "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
   "contactid":"b3546951-c543-e611-80d5-00155da84802",
   "account_primary_contact":[
      {
         "@odata.etag":"W/\"620919\"",
         "name":"Contoso, Ltd. (sample)",
         "accountid":"b2546951-c543-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contact 'Yvonne McKay (sample)' is the primary contact for the following accounts:
    1) 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 de nombreux contacts via l'attribut contact_customer_accounts.

À l'aide de account EntityType, nous pouvons créer 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 HTTP

GET http://cc_WebAPI_ServiceURI/accounts(86546951-c543-e611-80d5-00155da84802)?$select=name&$expand=contact_customer_accounts($select=fullname,jobtitle,annualincome) HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 4073

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#accounts(name,contact_customer_accounts,contact_customer_accounts(fullname,jobtitle,annualincome))/$entity",
   "@odata.etag":"W/\"620921\"",
   "name":"Contoso, Ltd. (sample)",
   "accountid":"86546951-c543-e611-80d5-00155da84802",
   "contact_customer_accounts":[
      {
         "@odata.etag":"W/\"620847\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"8e546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620849\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"92546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620851\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"96546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620853\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"9a546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620855\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"9e546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620857\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"a2546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620859\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"a6546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620861\"",
         "fullname":"Rene Valdes (sample)",
         "jobtitle":"Data Analyst III",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$86,000.00",
         "annualincome":86000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"aa546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620863\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"ae546951-c543-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Account 'Contoso, Ltd. (sample)' has the following contact customers:
    1) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    2) Nancy Anderson (sample), Activities Manager, $55,500.00
    3) Maria Cambell (sample), Accounts Manager, $31,000.00
    4) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    5) Scott Konersmann (sample), Accounts Manager, $38,000.00
    6) Robert Lyon (sample), Senior Technician, $78,000.00
    7) Paul Cannon (sample), Ski Instructor, $68,500.00
    8) Rene Valdes (sample), Data Analyst III, $86,000.00
    9) 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 de account EntityType. 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 HTTP

GET http://cc_WebAPI_ServiceURI/accounts(86546951-c543-e611-80d5-00155da84802)?$select=name&$expand=primarycontactid($select=fullname,jobtitle,annualincome),contact_customer_accounts($select=fullname,jobtitle,annualincome),Account_Tasks($select=subject,description) HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Preference-Applied: odata.maxpagesize=10
Content-Length: 5093

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#accounts(name,primarycontactid,contact_customer_accounts,Account_Tasks,primarycontactid(fullname,jobtitle,annualincome),contact_customer_accounts(fullname,jobtitle,annualincome),Account_Tasks(subject,description))/$entity",
   "@odata.etag":"W/\"620921\"",
   "name":"Contoso, Ltd. (sample)",
   "accountid":"86546951-c543-e611-80d5-00155da84802",
   "primarycontactid":{
      "@odata.etag":"W/\"620726\"",
      "fullname":"Yvonne McKay (sample)",
      "jobtitle":"Coffee Master",
      "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
      "annualincome":45000.0000,
      "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
      "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
      "contactid":"87546951-c543-e611-80d5-00155da84802"
   },
   "contact_customer_accounts":[
      {
         "@odata.etag":"W/\"620847\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"8e546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620849\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"92546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620851\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"96546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620853\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"9a546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620855\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"9e546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620857\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"a2546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620859\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"a6546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620861\"",
         "fullname":"Rene Valdes (sample)",
         "jobtitle":"Data Analyst III",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$86,000.00",
         "annualincome":86000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"aa546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620863\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"ae546951-c543-e611-80d5-00155da84802"
      }
   ],
   "Account_Tasks":[
      {
         "@odata.etag":"W/\"620840\"",
         "subject":"Task 1",
         "description":"Task 1 description",
         "activityid":"8b546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620842\"",
         "subject":"Task 2",
         "description":"Task 2 description",
         "activityid":"8c546951-c543-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"620844\"",
         "subject":"Task 3",
         "description":"Task 3 description",
         "activityid":"8d546951-c543-e611-80d5-00155da84802"
      }
   ]
}

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 related contacts:
    1) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    2) Nancy Anderson (sample), Activities Manager, $55,500.00
    3) Maria Cambell (sample), Accounts Manager, $31,000.00
    4) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    5) Scott Konersmann (sample), Accounts Manager, $38,000.00
    6) Robert Lyon (sample), Senior Technician, $78,000.00
    7) Paul Cannon (sample), Ski Instructor, $68,500.00
    8) Rene Valdes (sample), Data Analyst III, $86,000.00
    9) Jim Glynn (sample), Senior International Sales Manager, $81,400.00
Account 'Contoso, Ltd. (sample)' has the following tasks:
    1) Task 1, Task 1 description
    2) Task 2, Task 2 description
    3) Task 3, Task 3 description

Requêtes FetchXML

Outre les opérations de filtre de la requête, l'API Web prend également en charge les requêtes FetchXML. FetchXml fournit une alternative pour définir des requêtes et des options supplémentaires pour effectuer des agrégations.Pour plus d'informations :Générer des requêtes avec FetchXML

Pour utiliser fetch xml vous devez composer une chaîne représentant la requête. Vérifiez que la chaîne de requête respecte le FetchXML schema. Avant que vous puissiez inclure la chaîne dans l'URL, vous devez coder la chaîne au format URL.

Toutes les options de requête que nous définirions normalement comme $select, $filter, et $orderby sont désormais définies dans le code XML. Dans cette opération, 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 cette 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" />
    </filter>
  </entity>
</fetch>

Demande HTTP

La chaîne de requête de demande est envoyée au serveur dans un format encodé. L'en-tête encodé se présente comme suit.

GET http://cc_WebAPI_ServiceURI/contacts?fetchXml=%253Cfetch%2520mapping%253D%2522logical%2522%2520output-format%253D%2522xml-platform%2522%2520version%253D%25221.0%2522%2520distinct%253D%2522false%2522%253E%2520%2520%2520%253Centity%2520name%253D%2522contact%2522%253E%2520%2520%2520%2520%2520%253Cattribute%2520name%253D%2522fullname%2522%2520%252F%253E%2520%2520%2520%2520%2520%253Cattribute%2520name%253D%2522jobtitle%2522%2520%252F%253E%2520%2520%2520%2520%2520%253Cattribute%2520name%253D%2522annualincome%2522%2520%252F%253E%2520%2520%2520%2520%2520%253Corder%2520descending%253D%2522true%2522%2520attribute%253D%2522fullname%2522%2520%252F%253E%2520%2520%2520%2520%2520%253Cfilter%2520type%253D%2522and%2522%253E%2520%2520%2520%2520%2520%2520%2520%253Ccondition%2520value%253D%2522%2525(sample)%2525%2522%2520attribute%253D%2522fullname%2522%2520operator%253D%2522like%2522%2520%252F%253E%2520%2520%2520%2520%2520%253C%252Ffilter%253E%2520%2520%2520%253C%252Fentity%253E%2520%253C%252Ffetch%253E%2520 HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Content-Length: 4345

{
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome,_transactioncurrencyid_value,transactioncurrencyid,contactid)",
   "value":[
      {
         "@odata.etag":"W/\"621502\"",
         "fullname":"Yvonne McKay (sample)",
         "jobtitle":"Coffee Master",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$45,000.00",
         "annualincome":45000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"9255b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621627\"",
         "fullname":"Susanna Stubberod (sample)",
         "jobtitle":"Senior Purchaser",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$52,000.00",
         "annualincome":52000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"9955b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621635\"",
         "fullname":"Scott Konersmann (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$38,000.00",
         "annualincome":38000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"a955b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621637\"",
         "fullname":"Robert Lyon (sample)",
         "jobtitle":"Senior Technician",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$78,000.00",
         "annualincome":78000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"ad55b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621641\"",
         "fullname":"Rene Valdes (sample)",
         "jobtitle":"Data Analyst III",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$86,000.00",
         "annualincome":86000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"b555b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621639\"",
         "fullname":"Paul Cannon (sample)",
         "jobtitle":"Ski Instructor",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$68,500.00",
         "annualincome":68500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"b155b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621629\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"9d55b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621633\"",
         "fullname":"Nancy Anderson (sample)",
         "jobtitle":"Logistics Specialist",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$63,500.00",
         "annualincome":63500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"a555b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621631\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"a155b257-c843-e611-80d5-00155da84802"
      },
      {
         "@odata.etag":"W/\"621643\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"b955b257-c843-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts Fetched by fullname containing '(sample)':
    1) Yvonne McKay (sample), Coffee Master, $45,000.00
    2) Susanna Stubberod (sample), Senior Purchaser, $52,000.00
    3) Scott Konersmann (sample), Accounts Manager, $38,000.00
    4) Robert Lyon (sample), Senior Technician, $78,000.00
    5) Rene Valdes (sample), Data Analyst III, $86,000.00
    6) Paul Cannon (sample), Ski Instructor, $68,500.00
    7) Nancy Anderson (sample), Activities Manager, $55,500.00
    8) Nancy Anderson (sample), Logistics Specialist, $63,500.00
    9) Maria Cambell (sample), Accounts Manager, $31,000.00
    10) Jim Glynn (sample), Senior International Sales Manager, $81,400.00

Pagination FetchXML

La manière dont FetchXML gère la pagination est différente de celle dont le filtre de requête le gère. Dans FetchXML, vous pouvez spécifier un attribut count qui indique le nombre de résultats à renvoyer par page. Dans la même demande, utilisez l'attribut page pour spécifier le numéro de la page que vous souhaitez. Cette opération créera une demande de la page 3 de l'exemple FetchXML précédent. Selon nos exemples de données, nous devons avoir dix contacts dans notre résultat. En limitant chaque page à quatre entités par page, nous devrions avoir trois pages. La page 3 devrait contenir seulement deux entités. Si nous demandons ensuite la page 4, le système renverra zéro résultat.

<fetch mapping="logical"
       output-format="xml-platform"
       version="1.0"
       distinct="false"
       page="3"
       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" />
    </filter>
  </entity>
</fetch>

Demande HTTP

La chaîne de requête de demande est envoyée au serveur dans un format encodé. L'en-tête encodé se présente comme suit.

GET http://cc_WebAPI_ServiceURI/contacts?fetchXml=%253Cfetch%2520mapping%253D%2522logical%2522%2520output-format%253D%2522xml-platform%2522%2520version%253D%25221.0%2522%2520distinct%253D%2522false%2522%2520page%253D%25223%2522%2520count%253D%25224%2522%253E%2520%2520%2520%253Centity%2520name%253D%2522contact%2522%253E%2520%2520%2520%2520%2520%253Cattribute%2520name%253D%2522fullname%2522%2520%252F%253E%2520%2520%2520%2520%2520%253Cattribute%2520name%253D%2522jobtitle%2522%2520%252F%253E%2520%2520%2520%2520%2520%253Cattribute%2520name%253D%2522annualincome%2522%2520%252F%253E%2520%2520%2520%2520%2520%253Corder%2520descending%253D%2522true%2522%2520attribute%253D%2522fullname%2522%2520%252F%253E%2520%2520%2520%2520%2520%253Cfilter%2520type%253D%2522and%2522%253E%2520%2520%2520%2520%2520%2520%2520%253Ccondition%2520value%253D%2522%2525(sample)%2525%2522%2520attribute%253D%2522fullname%2522%2520operator%253D%2522like%2522%2520%252F%253E%2520%2520%2520%2520%2520%253C%252Ffilter%253E%2520%2520%2520%253C%252Fentity%253E%2520%253C%252Ffetch%253E%2520 HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Content-Length: 1037

{ 
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,jobtitle,annualincome,_transactioncurrencyid_value,transactioncurrencyid,contactid)",
   "value":[ 
      { 
         "@odata.etag":"W/\"621631\"",
         "fullname":"Maria Cambell (sample)",
         "jobtitle":"Accounts Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$31,000.00",
         "annualincome":31000.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"a155b257-c843-e611-80d5-00155da84802"
      },
      { 
         "@odata.etag":"W/\"621643\"",
         "fullname":"Jim Glynn (sample)",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802",
         "contactid":"b955b257-c843-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

Contacts Fetched by fullname containing '(sample)' - Page 3:
    1) Maria Cambell (sample), Accounts Manager, $31,000.00
    2) Jim Glynn (sample), Senior International Sales Manager, $81,400.00

Requêtes prédéfinies

Vous pouvez utiliser l'API Web pour exécuter des requêtes prédéfinies.Pour plus d'informations :Extraire 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.

Obtention du GUID de la requête enregistré.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/savedqueries?$select=name,savedqueryid&$filter=name%20eq%20'Active%20Accounts' HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue
Referer: https://localhost:1469/WebAPIQuery.html

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Content-Length: 251

{ 
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#savedqueries(name,savedqueryid)",
   "value":[ 
      { 
         "@odata.etag":"W/\"443067\"",
         "name":"Active Accounts",
         "savedqueryid":"00000000-0000-0000-00aa-000010001002"
      }
   ]
}

Obtention du contenu de la requête enregistré en utilisant le paramètre savedQuery

Demande HTTP

GET http://cc_WebAPI_ServiceURI/accounts?savedQuery=00000000-0000-0000-00aa-000010001002 HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
REQ_ID: 2bc532c4-d445-44cd-adae-1909a616d6bc
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Content-Length: 446

{ 
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#accounts(name,_primarycontactid_value,primarycontactid,accountid)",
   "value":[ 
      { 
         "@odata.etag":"W/\"621613\"",
         "name":"Contoso, Ltd. (sample)",
         "_primarycontactid_value@OData.Community.Display.V1.FormattedValue":"Yvonne McKay (sample)",
         "_primarycontactid_value":"9255b257-c843-e611-80d5-00155da84802",
         "accountid":"9155b257-c843-e611-80d5-00155da84802"
      }
   ]
}

Sortie de la console

-- Saved Query -- 
Saved Query (Active Accounts):
    1) Contoso, Ltd. (sample)

Requête utilisateur

Cet exemple crée une requête utilisateur, l'exécute, puis la supprime du système. 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 à cette requête.

Obtention du GUID de la requête utilisateur enregistré.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/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
Referer: https://localhost:1469/WebAPIQuery.html

Réponse HTTP

Pragma: no-cache
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Content-Length: 246

{ 
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#userqueries(name,userqueryid)",
   "value":[ 
      { 
         "@odata.etag":"W/\"621698\"",
         "name":"My User Query",
         "userqueryid":"7ec390ab-c943-e611-80d5-00155da84802"
      }
   ]
}

Obtention du contenu de la requête utilisateur transmettant la valeur GUID au paramètre userQuery.

Demande HTTP

GET http://cc_WebAPI_ServiceURI/contacts?userQuery=7ec390ab-c943-e611-80d5-00155da84802 HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json; charset=utf-8
Prefer: odata.maxpagesize=10, odata.include-annotations=OData.Community.Display.V1.FormattedValue

Réponse HTTP

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Content-Length: 1040

{ 
   "@odata.context":"http://cc_WebAPI_ServiceURI/$metadata#contacts(fullname,contactid,jobtitle,annualincome,_transactioncurrencyid_value,transactioncurrencyid)",
   "value":[ 
      { 
         "@odata.etag":"W/\"621643\"",
         "fullname":"Jim Glynn (sample)",
         "contactid":"b955b257-c843-e611-80d5-00155da84802",
         "jobtitle":"Senior International Sales Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$81,400.00",
         "annualincome":81400.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802"
      },
      { 
         "@odata.etag":"W/\"621629\"",
         "fullname":"Nancy Anderson (sample)",
         "contactid":"9d55b257-c843-e611-80d5-00155da84802",
         "jobtitle":"Activities Manager",
         "annualincome@OData.Community.Display.V1.FormattedValue":"$55,500.00",
         "annualincome":55500.0000,
         "_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue":"US Dollar",
         "_transactioncurrencyid_value":"518c78c9-d3f6-e511-80d0-00155da84802"
      }
   ]
}

Sortie de la console

-- User Query -- 
Saved User Query:
    1) Jim Glynn (sample), Senior International Sales Manager, $81,400.00
    2) Nancy Anderson (sample), Activities Manager, $55,500.00

Voir aussi

Utilisez l'API Web Microsoft Dynamics 365
Interroger les 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)

Microsoft Dynamics 365

© 2017 Microsoft. Tous droits réservés. Copyright