Recommended methodology

When building API queries, follow this process:
  1. Identify the data needed for a given purpose — Which data do I need to get.

  2. Explore the fieldsExperience Cloud stores data in records, and each record is a set of fields; fields store the data. As such, you need to identify the fields that store the data you need.

    The API provides field-filtering mechanism to identify the field(s) you need.

    The API also provides a way to query the metadata associated with the fields, such as data types, options, etc).

  3. Write and test the query — Once you know which fields and their data types, the easier task is writing the query.

    To write the query, any GraphQL editor could be used (Chrome users could use Altair GraphQL Client). The editor will connect with the API endpoint, will download the schema (behind the scenes) and with that will provide auto-complete feature while writing the query. The API Docs also will be shown in the tool. The same editor will allow you test the API and see in the same screen the query and the results.

  4. Optimize — GraphQL is very versatile, but its flexibility also allows you to build non-performant queries. To avoid impacting system performance, Experience Cloud throttles poor-performant queries. The cost of such queries will be a reduced quota in the number of queries you can make.

    To assist you in optimizing your queries, you can ask "the cost" of executing the query without actually executing the query! The cost is a value indicating the impact on the system. Reduce the cost by comparing the value of various queries. Asking for the cost does not impact your query quota, so make as many "cost" requests as you need to optimize the performance.
    Note: Consult GraphQL best practices documentation for tips on optimizing the cost.

Reference implementation

You can also check the following reference implementation:

https://github.com/medallia/query-api-data-extract

Analyze the code and evaluate your own internal version against the best practices established here.
Important: This implementation is merely a point of reference and is not intended for productive use.