Ejemplo de datos de consulta de la API web

Use este grupo de código de ejemplo para aprender a consultar datos utilizando la API web de Microsoft Dataverse. Este ejemplo se implementa como proyecto independiente para los siguientes idiomas:

En este tema se describe un conjunto común de operaciones implementadas por cada ejemplo en este grupo. En este tema se describen las solicitudes y las respuestas HTTP y el texto generado que cada ejemplo en este grupo realizará sin detalles específicos de idioma. Consulte las descripciones específicas del idioma y los ejemplos individuales para obtener más información acerca de cómo se realizan estas operaciones.

Demostraciones

Este ejemplo se divide en las siguientes secciones principales, que contienen operaciones de datos de consulta de la API web que se describen minuciosamente en los temas conceptuales asociados.

Sección del tema Temas asociados
Sección 1: Seleccionar propiedades específicas Recuperar propiedades específicas
Valores formateados
Sección 2: Usar funciones de consulta Filtrar filas
Utilice las funciones de consulta de OData
Crear una consulta con funciones
Web API Query Function Reference
Sección 3: Pedidos y alias Ordenar filas
Filtrar filas
Sección 4: Limitar y contar los resultados Limitar el número de filas
Contar el número de filas
Sección 5: Paginación Resultados de la página
Sección 6: Expandir resultados Unir tablas
Sección 7: Agregación de resultados Información agregada
Sección 8: FetchXML consultas Referencia de FetchXml
Consultar datos mediante FetchXML
Sección 9: Usar consultas predefinidas Recuperar y ejecutar consultas predefinidas
userquery EntityType
savedquery EntityType
Sección 10: Eliminar registros de muestra Eliminación básica
Ejecute las operaciones por lotes mediante API web

Las siguientes secciones contienen una breve explicación de las operaciones de la API web de Dataverse realizadas, junto con mensajes HTTP correspondientes y la salida asociada de la consola.

Sección 0: Crear registros para consultar

El código de muestra crea un conjunto de filas de muestra para consultar. El código elimina los datos al final a menos que elija conservarlos. Puede obtener resultados diferentes en función de los datos existentes en el entorno.

Los datos se agregan mediante inserción profunda en una sola solicitud de POST y coinciden con la estructura siguiente:

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

Sección 1: Seleccionar propiedades específicas

Incluya siempre la opción de consulta $select en sus consultas. Si no lo hace, el servidor devuelve todas las propiedades de cada fila de la tabla, lo que reduce el rendimiento. Aprenda a crear columnas Seleccionar.

Este ejemplo demuestra cómo generar una consulta básica seleccionando tres propiedades de un contact EntityType. Las propiedades son fullname, jobtitle, annualincome. La sección también ilustra las diferencias entre formateado y valores sin formato como se ven en los resultados del contacto. annualincome propiedad.

En este ejemplo, solicitamos un contacto específico. En este caso, es el contacto principal de la cuenta, Yvonne McKay (sample).

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Sección 2: Usar funciones de consulta

Use opciones de filtro para establecer criterios para los resultados deseados. Puede crear filtros sencillos y complejos con una combinación de funciones de consulta, operadores de comparación, y operadores lógicos. Más información: Filtrar filas

Las funciones de consulta son funciones que puede usar como criterios de filtro en una consulta. Estas funciones aceptan parámetros y devuelven un valor Boolean. Existen funciones de consulta estándar y funciones de Dataverse de consulta específicas. En este ejemplo se muestra cómo crear una consulta para cada tipo.

Funciones estándar de consulta

Dataverse admite un subconjunto de funciones de consulta integradas de OData, específicamente: contains, endswith y startswith. Por ejemplo, la función de consulta estándar contains le permite filtrar las propiedades que coincidan con una cadena. Más información: Utilice las funciones de consulta de OData

En esta operación, consultamos todos los contactos con fullname que contienen la cadena (sample).

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Funciones de consulta de Dataverse

Las funciones de consulta de Dataverse proporcionan varias opciones para generar consultas que son relevantes para Dataverse. Para obtener una lista completa de estas funciones, consulte Web API Query Function Reference. Más información: Crear una consulta con funciones

Las funciones de consulta de YDataverse son similares a las funciones de consulta estándar. La diferencia principal es que cuando usa funciones de consulta de Dataverse, debe proporcionar el nombre completo de la función incluidos los nombres de parámetros. Por ejemplo, para obtener una lista de contactos creados en la última hora, puede generar una consulta mediante la función LastXHours.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Usar operadores

Usar operadores de comparación y operadores logicos (eq,ne,gt,ge,lt,le,and,or,not) para refinar aún más sus resultados. En este ejemplo, solicitamos una lista de todos los contactos donde fullname contiene (sample) y los ingresos anuales son mayores que 55000.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Establecer prioridad

Dado que todos los operadores tienen la misma precedencia, utilice paréntesis para establecer el orden en que se evalúan las condiciones de consulta. Los filtros se aplican de izquierda a derecha. El orden en el que estas instrucciones aparecen en el filtro puede afectar a los resultados.

En este ejemplo, solicitamos una lista de todos los contactos donde fullname contiene (sample), jobtitle contiene senior o manager y annualincome es mayor que 55000. Para obtener los resultados deseados, debemos usar paréntesis para agrupar los filtros jobtitle. Si no lo hacemos, el operador or tiene la misma precedencia que los operadores and. La consulta en este ejemplo es similar a esta: $filter=contains(fullname,'(sample)') and (contains(jobtitle,'senior') or contains(jobtitle,'manager')) and annualincome gt 55000.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Sección 3: Pedidos y alias

Ordenar resultados

Para ordenar los resultados en sentido ascendente o descendente, use la opción de filtro $orderby. En este ejemplo, consultaremos para todos los contactos con fullname que contiene (sample) y solicitaremos los datos en orden ascendente en función del valor de propiedad jobtitle y luego en orden descendente basado en el valor de propiedad annualincome usando esta sintaxis: $orderby=jobtitle asc, annualincome desc. Más información: Ordenar filas

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Alias de parámetro

Usar alias de parámetros para reutilizar más fácilmente los parámetros en sus filtros. Puede usar alias en las opciones $filter y $orderby. Si al alias no se asigna un valor se da por hecho que es nulo.

También puede usar alias de parámetro al llamar funciones. Por ejemplo, podemos reescribir la consulta de la operación de resultados con el orden anterior para usar parámetros y obtener la misma salida.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Sección 4: Limitar y contar los resultados

Como práctica recomendada, no devuelva más datos de los que necesita. Para proteger el rendimiento, el servidor devuelve un máximo de 5000 filas de tabla por solicitud.

Para limitar el número de resultados devueltos, utilizar el $top Opción de consulta o añadir odata.maxpagesize en el encabezado de la solicitud. La opción de consulta $top devuelve el número superior de filas del conjunto de resultados e ignora el resto. El encabezado de solicitud odata.maxpagesize especifica el número de filas para devolver por página con una propiedad @odata.nextLink para obtener los resultados de la página siguiente. Obtenga más información sobre los resultados de la página.

Resultados relevantes

Podemos aplicar la opción de consulta $top para limitar la operación de consulta básica a los cinco primeros contactos con fullname que contienen (sample). En este caso, la solicitud genera realmente al menos 10 resultados, pero solo las primeras 5 entradas se devuelven en la respuesta.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Recuento de colección

Si solo desea la cantidad de registros en una colección, agregue /$count a la URL de la colección. El valor máximo es 5,000.

Solicitud:

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

Respuesta:

HTTP/1.1 200 OK
OData-Version: 4.0

9

Salida de la consola:

The contacts collection has 9 contacts.

Número de resultados

Puedes obtener el recuento de filas de una propiedad con valor de colección o un recuento de filas de tabla coincidentes en un filtro. El recuento les dice el número de filas posibles en su resultado. Sin embargo, el servidor de Dataverse devuelve 5000 como recuento máximo, aunque el resultado puede tener más.

En este ejemplo, construimos un filtro donde jobtitle contiene Senior o Manager y también solicitamos un $count del resultado. La respuesta contiene el recuento en la propiedad @odata.count junto con los resultados de la consulta.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Sección 5: Paginación

Algunas consultas devuelven una gran cantidad de filas y es más fácil verlas una página a la vez. A recuperar resultados paginados, utilizar el odata.maxpagesize Opción en lugar de $top.

En este ejemplo, pedimos $count y establecemos odata.maxpagesize como 4. Este filtro coincide con 10 contactos, pero solo estamos recuperando 4 a la vez. También usamos el recuento y el tamaño máximo de página para averiguar el número de páginas que hay. El resultado de la primera página se devuelve en esta solicitud.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Para recuperar la página 2, use una solicitud GET con el valor de la propiedad @odata.nextLink.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Sección 6: Expandir resultados

Para recuperar información sobre las filas de la tabla asociadas, utilice la opción de consulta $expand sobre las propiedades de navegación. Más información: Unir tablas

Expandir la propiedad de navegación de un solo valor

Una propiedad de navegación de un solo valor representa una relación de varios a uno. En nuestros datos de muestra, la cuenta tiene una relación con un contacto a través de la columna primarycontactid o atributo. En esta relación, la cuenta solo puede tener solo un contacto principal. Con el EntityType de cuenta, podemos crear una consulta para obtener información sobre la cuenta y información ampliada sobre su contacto principal.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Expandir la propiedad de asociados

Cada propiedad de navegación tiene una propiedad “partner" correspondiente. Después de que se crea una asociación, podemos recuperar la información a través de esta. La columna que usemos depende de la tabla base que consultemos.

Por ejemplo, en la operación anterior, creamos una consulta contra el tipo de entidad de cuenta. Queríamos obtener más información sobre su contacto principal, por lo que usamos la columna o atributo primarycontactid. Si buscamos el tipo de entidad de cuenta, en la sección de propiedades de navegación de valor único encontramos que el socio propiedad de primarycontactid es la propiedad de navegación con valor de colección account_primary_contact que se encuentra en el tipo de entidad de contacto.

Si genera una consulta contra un contacto, puede ampliar la columna account_primary_contact para obtener información sobre las cuentas en las que el contacto es el contacto principal. En los datos de ejemplo, Yvonne McKay (sample) es la persona de contacto principal únicamente para una cuenta. Sin embargo, Yvonne puede asignarse potencialmente a otras cuentas como el contacto principal. Porque la propiedad account_primary_contact tiene una relación de muchos a uno, el resultado se devuelve como una matriz de filas de cuenta.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Expandir la propiedad de navegación valorada como colección

Las propiedades de navegación valoradas como colección admiten relaciones de uno a varios o de varios a varios. Por ejemplo, en nuestros datos de muestra, la cuenta tiene una relación con muchos contactos a través de la columna contact_customer_accounts o atributo.

Podemos usar el tipo de entidad de cuenta en una consulta para obtener información sobre la cuenta y expanda información sobre sus contactos. En este caso, el Contoso, Ltd. (sample) se asocia a nueve contactos mediante la propiedad de navegación valorada como colección contact_customer_accounts.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Expandir varias propiedades de navegación

Puede expandir tantas propiedades de navegación como la consulta requiera. Sin embargo, la opción $expand solo puede ir a un nivel de profundidad.

Este ejemplo expande las propiedades de navegación primarycontactid, contact_customer_accounts y Account_Tasks del tipo de entidad de cuenta. La consulta devuelve una respuesta que contiene información sobre la cuenta y dos colecciones: una colección de contactos y una colección de tareas. El código de ejemplo procesa las colecciones de forma independiente.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

-- Expanding multiple property types in one request --

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

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

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

Expansión multinivel

Con las propiedades de navegación de un solo valor, puede usar $expand para continuar subiendo varios niveles usando solo propiedades de navegación de un solo valor. Esta consulta comienza con registros task y amplía los datos de lsa tablas contact, account y systemuser usando solo propiedades de navegación de un solo valor.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Sección 7: Agregación de resultados

Para devolver valores agregados, utilice la opción $apply. Este ejemplo aplica average, sum, min y max a los valores de ingresos anuales.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Sección 8: FetchXML consultas

Además de las operaciones de filtrado de consultas, la API web también admite FetchXML consultas. FetchXML Proporciona una forma alternativa de definir consultas y más opciones de agregación. Todas las opciones de consulta que definiríamos normalmente, como $select, $filter y $orderby, ahora se definen en el XML.

Usar FetchXML, compone una cadena que representa la consulta. Asegúrese de que la cadena de consulta se ajuste a la referencia de FetchXml. Antes de incluir la cadena en la URL, debe codificarla como URL.

En este ejemplo, consultamos todos los contactos donde fullname coincide con (sample) y devuelve los resultados en orden descendente por fullname.

Este es el XML para la consulta:

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

En este ejemplo, la consulta se envía mediante una solicitud $batch. FetchXML Las consultas pueden ser largas, por lo que pueden alcanzar los límites de URL que se pueden enviar mediante GET. Con una operación $batch, la URL se envía en el cuerpo de la solicitud, donde los límites son más altos.

Solicitud:

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

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

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


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

Respuesta:

HTTP/1.1 200 OK
OData-Version: 4.0

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

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

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

Salida de la consola:

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

FetchXML paginación

El camino FetchXML La forma en que se maneja la paginación es diferente a como la maneja un filtro de consulta. En FetchXML, puedes especificar un count Columna que indica cuántos resultados devolver por página. En la misma solicitud, usa la columna page para especificar el número de página para devolver.

La siguiente operación solicita la página 2 de la anterior. FetchXML muestra. En función de nuestros datos de ejemplo, deberíamos tener ocho contactos en nuestro resultado. Al dividir cada página en solo cuatro contactos por página, deberíamos tener dos páginas. La página 2 debe contener solo cuatro contactos. Si a continuación pedimos la página 3, el sistema devuelve cero resultados.

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

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

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

Sección 9: Usar consultas predefinidas

Puede usar la API web para recuperar y ejecutar consultas predefinidas.

Consulta guardada

En esta operación, solicitamos el GUID savedqueryid de la consulta guardada con el nombre Cuentas activas. A continuación usamos el GUID y el parámetro savedQuery para consultar una lista de cuentas activas.

Primero, obtenemos el GUID de la consulta guardada.

Solicitud:

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

Respuesta:

HTTP/1.1 200 OK
OData-Version: 4.0

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

Luego usamos el parámetro savedQuery para obtener contenido de la consulta guardada.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

-- Saved Query --

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

Consulta de usuario

Este ejemplo crea una consulta de usuario, la ejecuta y luego la elimina del sistema.

Solicitud:

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

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

Respuesta:

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

Esta consulta de usuario pide contactos donde fullname contiene (sample), jobtitle contiene manager, y annualincome es mayor que 55000. Nuestros datos de ejemplo tiene dos contactos que coinciden con esta consulta.

En el código de ejemplo, el valor userqueryid se devuelve con la solicitud que lo crea. Normalmente, necesitaría consultar el sistema para recuperarlo mediante una consulta como la siguiente:

Solicitud:

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

Respuesta:

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

Este ejemplo pasa el valor GUID con el parámetro userQuery para obtener el contenido de la consulta del usuario.

Solicitud:

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

Respuesta:

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

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

Salida de la consola:

-- User Query --

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

Sección 10: Eliminar registros de muestra

Use una operación $batch para eliminar todos los registros creados en la Sección 0: Crear registros para consultar.

Solicitud:

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

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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

Respuesta:

HTTP/1.1 200 OK
OData-Version: 4.0

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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

HTTP/1.1 204 No Content
OData-Version: 4.0


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

Consulte también

Usar la API web de Dataverse
Consultar datos mediante la API web
Recuperar y ejecutar consultas predefinidas
Ejemplo de datos de consulta API (C#)
Ejemplo de datos de consulta de la API web (JavaScript del lado del cliente)

Nota

¿Puede indicarnos sus preferencias de idioma de documentación? Realice una breve encuesta. (tenga en cuenta que esta encuesta está en inglés)

La encuesta durará unos siete minutos. No se recopilan datos personales (declaración de privacidad).