GitHub REST API marked_as_duplicate timeline event doesn't include the canonical issue #201055
-
🏷️ Discussion TypeQuestion 💬 Feature/Topic AreaAPI BodyI'm using the GitHub REST API timeline endpoint for issues: GET /repos/{owner}/{repo}/issues/{issue_number}/timeline When an issue is marked as a duplicate, I receive a timeline event like this: { However, I can't find any field that identifies the canonical issue that this issue was marked as a duplicate of. I was expecting something like a canonical, duplicate_of, or similar field, but none is present. Is there a way to obtain the canonical issue using the REST API, or is this only available through the GraphQL API or by parsing comments? Any clarification would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
I looked at the requests GitHub makes on the issue page and found the GraphQL IssueViewerViewQuery. That response contains: "duplicateOf": { which is exactly what I'm looking for. Is there any way to get this through the REST API, or is duplicateOf only exposed through GraphQL? Feels a bit strange that the website has access to it but the REST API doesn't. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @xe0896 ! I've run into this exact same limitation. You are completely right. the REST API payload for the While we wait for GitHub to patch this on the REST side, here are two workarounds you can use depending on your stack: Workaround 1: Use the GraphQL APIGitHub's GraphQL API is generally more up-to-date with entity relationships. The You can fetch the exact timeline event and the original issue number using this query: query {
repository(owner: "OWNER", name: "REPO") {
issue(number: YOUR_ISSUE_NUMBER) {
timelineItems(first: 50, itemTypes: [MARKED_AS_DUPLICATE_EVENT]) {
nodes {
... on MarkedAsDuplicateEvent {
createdAt
actor {
login
}
canonical {
... on Issue {
number
url
}
... on PullRequest {
number
url
}
}
}
}
}
}
}
}
Workaround 2: The REST API "Hack" (Parsing Cross-References)If you are strictly locked into the REST API and can't use GraphQL, you have to reconstruct the relationship via the timeline. When a user marks an issue as a duplicate, GitHub automatically creates a
It's a bit hacky to rely on timestamps, but it reliably bridges the gap if you are building an automated triage bot or webhook handler purely in REST. Hope this helps unblock you! |
Beta Was this translation helpful? Give feedback.
Hey @xe0896 ! I've run into this exact same limitation. You are completely right. the REST API payload for the
marked_as_duplicatetimeline event is currently missing the reference to the canonical (original) issue.While we wait for GitHub to patch this on the REST side, here are two workarounds you can use depending on your stack:
Workaround 1: Use the GraphQL API
GitHub's GraphQL API is generally more up-to-date with entity relationships. The
MarkedAsDuplicateEventin GraphQL actually exposes thecanonicalfield.You can fetch the exact timeline event and the original issue number using this query: