Queries Library
Queries LibraryRetrieve user data stored in a different WordPress site

Retrieve user data stored in a different WordPress site

This query fetches the user data (from a WordPress site) stored on a different WordPress site, using the user's slug as the common identifier between the 2 sites.

It works by executing the /users REST API endpoint on the remote site, while passing the users' slugs to retrieve those results only.

query GetUserSlugs {
  users(pagination: { limit: -1 }) {
    id
    slug
      @export(
        as: "userSlugs",
        type: LIST,
      )
  }
}
 
query FetchUserDataFromAnotherWPSite(
  # URL of the remote /users REST API endpoint
  # eg: https://somesite.com/wp-json/wp/v2/users
  $endpointURL: URL!
)
  @depends(on: "GetUserSlugs")
{
  endpoint: _urlAddParams(
    url: $endpointURL,
    params: {
      slug: $userSlugs
    }
  )
 
  remoteUserData: _sendJSONObjectCollectionHTTPRequest(
    input: {
      url: $__endpoint,
      method: GET
    }
  )
}