HomeDev guideRecipesAPI ReferenceGraphQL
Dev guideUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Modified and deleted content items

How to get content items based on last modified changes.

Modified documents

With Optimizely Graph, you can query for updates to content items. This can be useful to get snapshots of content items based on a datetime delta using the cursor. It can also be used as a signal to know when a static site should be re-generated. The hit count with total can be used to know whether a site has fully synchronized.

We can get the first 5 modified documents updated since 2023-05-24T11:00 with this Optimizely Graph query:

{
  Content(
    limit: 5, 
    where: { _modified: { gte: "2023-05-24T11:00" } }
    orderBy: {_ranking: DOC}
  ) {
    total
    items {
      _modified
      ContentLink {
        GuidValue
      }
    }
  }
}

We can get all the modified documents updated since 2023-05-24T11:00 with this Optimizely Graph query using cursor:

{
  Content(
    limit: 5, 
    where: { _modified: { gte: "2023-05-24T11:00" } }
    orderBy: {_ranking: DOC}
    cursor: ""
  ) {
    total
    items {
      _modified
      ContentLink {
        GuidValue
      }
    }
    cursor
  }
}

And you can get the next batches of the modified content by adding the cursor value to the cursor argument.

Deleted documents

It is possible in Optimizely Graph to query for content items that have been deleted. This is only possible by using HMAC authentication and adding the header cg-include-deleted with value true. Each content item that is deleted will have the value of _modified updated and is marked as deleted with _deleted: true.

With the single key, we only allow the retrieval of published content items, so the values of _deleted will always be null.

We can use the following Optimizely Graph query to get all modified content items, including deleted items, since 2023-05-20T11:00:

{
  Content(
    limit: 5, 
    where: { _modified: { gte: "2023-05-20T11:00" } }
    orderBy: {_ranking: DOC}
    cursor: ""
  ) {
    total
    items {
      _deleted
      ContentLink {
        GuidValue
      }
    }
    cursor
  }
}

You know that an item has been deleted by looking at the value of _deleted. When the value is true, the content item has been deleted. A response could look like this, and note that there are 3 deleted items in this batch.

{
  "data": {
    "Content": {
      "total": 13,
      "items": [
        {
          "_deleted": null,
          "ContentLink": {
            "GuidValue": "64ea99b4-fe38-43b7-a993-20ceb333861a"
          }
        },
        {
          "_deleted": true,
          "ContentLink": {
            "GuidValue": "c8ab68cf-7231-43ca-a376-ca4cac2e06d8"
          }
        },
        {
          "_deleted": null,
          "ContentLink": {
            "GuidValue": "582ecd34-e0bc-4d14-b467-8255b04d2b53"
          }
        },
        {
          "_deleted": true,
          "ContentLink": {
            "GuidValue": "c64c5afb-a538-4245-92d8-55625527cfd3"
          }
        },
        {
          "_deleted": true,
          "ContentLink": {
            "GuidValue": "4eaece75-3e53-440b-8dec-eb8d6d6895e0"
          }
        }
      ],
      "cursor": "FGluY2x1ZGVfY29udGV4dF91dWlkDnF1ZXJ5VGhlbkZldGNoAhZua3ZXUUFvMFRuU2plVUJmX1pfTlNnAAAAAAAADwQWTG5QWjFjRXFURnVpZktRd0d0MkZGQRZua3ZXUUFvMFRuU2plVUJmX1pfTlNnAAAAAAAADwUWTG5QWjFjRXFURnVpZktRd0d0MkZGQQ=="
    }
  },
  "extensions": {
    "correlationId": "92151285-aae3-4d7f-93e7-a009d390f18e",
    "cost": 9,
    "costSummary": [
      "Content(9) = limit(5) + fields(2) + basicFilter(1)*2"
    ]
  }
}