7

If you follow and/or curate a tag long enough, you'll probably notice that there's some questions that just get asked over and over. Usually these are confusing aspects of some commonly used feature that newbies keep tripping over.

Having a gold tag badge, after I close these repeated duplicates, I also proceed to edit the duplicate list with more similar Q&As that are relevant to the issue1. For several very common duplicates, I often find myself editing the same duplicate list in every time. This is a repetitive and time-consuming task. I would like to automate it instead.

I would like to make an API call to cast a close vote as duplicate with a list of duplicate targets.

I'm aware of the API /questions/{id}/flags/add which can be used to cast close votes, however it's not clear to me how duplicate closure happens in this case. Where do I set the ID of the dupe target? There are examples in the options page but I don't understand how the available "Duplicate Free Form" and "Duplicate Pre-Filled" relate to my goal. Also testing the API requires an API key, which I don't have.

I also tried inspecting the network activity when closing a dupe from the GUI, though the endpoint used is different: /flags/questions/{id}/close/add. However this does have a closeReasonId: Duplicate and duplicateOfQuestionId: {id} form fields which look closer to my goal.

Can I call the internal endpoints in a userscript, with an array of (comma-separated?) items in duplicateOfQuestionId? Or is there a way to accomplish this with the public API and some flag option?


Footnotes:

1: One could argue that if those dupe targets consistently appear together in dupe lists, they are also dupes of each other and therefore should be merged. This may or may not be true, but it's beside the point.

10
  • The Stack Exchange API doesn't support it, but no doubt you can write a userscript which mimics the browser requests. Perhaps have a look here if you need help.
    – Glorfindel Mod
    Commented May 8, 2022 at 13:36
  • @Glorfindel thanks, is there any documentation about the API used by the browser? Ideally I would like to make one API call for this, instead of really mimicking what I do from the GUI — i.e. vote to close + edit dupe list
    – blackgreen
    Commented May 8, 2022 at 13:42
  • no, because it's not really meant to be used like that. We still do it :)
    – Glorfindel Mod
    Commented May 8, 2022 at 13:43
  • 1
    @blackgreen what's being used by the browser isn't API, it's AJAX calls to internal endpoints, with different code behind them. The API and those endpoints share methods for sure, but still, not same code at all. Commented May 8, 2022 at 13:47
  • 2
    Similar concern as this FR but I approached it from another angle: Add keyboard shortcut for editing the list of duplicates
    – VLAZ
    Commented May 8, 2022 at 14:18
  • 1
    UserScripters here - backlogged. As a quick FYI, SE API has a default API key when testing on the documentation page with the increased allowance of 10K requests per day. It also allows up to 300 unauthorized requests, but if you already have userscripts that consume the quota that might not be an option for you.
    – 0Valt
    Commented May 8, 2022 at 15:05
  • ^ scrap the above note about the API, it just dawned on me that you were talking about this specific method that requires auth.
    – 0Valt
    Commented May 8, 2022 at 15:15
  • What duplicate list? On the closed question? This? Commented May 8, 2022 at 21:52
  • @This_is_NOT_a_forum yes, the list of dupe links of questions closed as dupes
    – blackgreen
    Commented May 9, 2022 at 6:33
  • 1
    created userscript: stackapps.com/questions/9400/…
    – blackgreen
    Commented May 11, 2022 at 9:00

1 Answer 1

1

This feature appears to be not supported by the public API. As a workaround, it's possible to send two calls to the internal endpoints in sequence:

1. close the question

  • endpoint: /flags/questions/${questionId}/close/add
  • method: POST
  • 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  • Payload: POST form with:
key value
closeReasonId Duplicate
duplicateOfQuestionId question id
siteSpecificOtherText anything, placeholder
originalSiteSpecificOtherText anything, placeholder
fkey your fkey

Example payload as Javascript string:

`closeReasonId=Duplicate&duplicateOfQuestionId=${questionId}&siteSpecificOtherText=placeholder&originalSiteSpecificOtherText=placeholder&fkey=${fkey}`

2. edit the dupe list

  • endpoint: /questions/originals/${questionId}/save-originals
  • method: POST
  • 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  • Payload: POST form with:
key value
originalsIdsJson URI-encoded literal json array with ids of the dupe targets. I mean literally %5B + %2C-separated ids + %5D
fkey your fkey

Example payload as Javascript string:

const _targetIds = ["123", "456"]
const _originals = encodeURIComponent('[' + _targetIds.join(',') + ']')
const _payload = `originalsIdsJson=${_originals}&fkey=${fkey}`

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .