Sideloading related records

Sometimes you need data from two different APIs. For example, suppose you want to list the authors of Help Center articles. The records returned by thearticles APIidentify authors only by their Zendesk Support user id, not by their actual names:

             
{"articles":[{"author_id":3465,...},...]}

The articles API doesn't return user names, but theusers APIcertainly does. One option might be to call the users API for each article in your results set. This involves hitting the users API repeatedly. Not very efficient.

To avoid unneccesary API calls, you cansideloadone set of records with another. Sideloading lets you get both sets of records in a single request. For example, to sideload users, add theinclude=usersURL parameter to the articles endpoint:

             
旋度https://{subdomain}.亚博.com/api/v2/help_center/fr/articles.json?include=users \-v-u{email_address}:{password}

Where previously the API returned a list of articles, the API now also returns a list of users specified in the articles:

             
{"articles":[{"author_id":3465,...},...],“用户”:[{'id':3465,'name':'Bob Bobberson',...}]}

Critically, the API doesn't get all the users in your Zendesk Support instance. It gets only the users specified in the list of articles. So listing the articles' authors becomes a simple matter of listing the names of the sideloaded users. Example:

             
url='.../api/v2/help_center/fr/articles.json?include=users'response=session.get(url)data=response.json()foruserindata['users']:print(user['name'])

Sideloaded records include only a subset of the resource's properties. For example, the sideloaded records in the example above only include theid,name, andphotouser properties. Run the request in旋度to learn the included properties of sideloaded records.

The articles API lets you sideload users, sections, categories, and translations. See theAPI文档for the specific resources you can sideload with other APIs, if any.

For a tutorial that covers sideloading along the way, seeList the followers of a KB section.