0

I am able to retrieve a list of all my answers, within a given date range, by using this below curl command:

curl "https://api.stackexchange.com/2.2/users/10348758/answers?page=1&pagesize=100&fromdate=1588291200&todate=1592179200&order=desc&sort=activity&site=stackoverflow&access_token=my-access-token&key=my-key" | gunzip

I need to find the list of my unaccepted answers within a given date range.

According to the documentation, these fields can be applied to the answer type.

In the documentation, it is written that:

The upvoted, downvoted, and accepted fields can only be queried for with an access_token with the private_info scope.

So, I have also created access_token with the scope being private_info.

I have modified my command in the following way :

curl "https://api.stackexchange.com/2.2/users/10348758/answers?is_accepted=false?page=1&pagesize=100&fromdate=1588291200&todate=1592179200&order=desc&sort=activity&site=stackoverflow" | gunzip

In the above command, I have added the is_accepted=false parameter, but I am getting the same result as the above command i.e. I am getting a complete list of answers. I want to retrieve only those answers of mine which are unaccepted (within a given date range). Do I need to apply a filter in the curl command?

How can I retrieve a list of all my unaccepted answers (within a given date range) using Stack Exchange API?

double-beep
  • 5,031
  • 17
  • 33
  • 41
ESCoder
  • 15,431
  • 2
  • 19
  • 42
  • You do not need to pass your access token as a parameter in the `users/{ids}/answers` method. You need in [the methods](https://api.stackexchange.com/docs) that have `auth required` next to their description and to all the `/me/` methods. – double-beep Jul 08 '20 at 07:21

1 Answers1

3

is_accepted is one of the fields. And, in the current stage, it seems that this cannot be used for filtering the result values as the query parameter.

From this situation, how about the following workaround? I would like to propose to use jq for filtering the retrieved values. In this workaround, the values with is_accepted: false are retrieved from the all retrieved values using jq.

Sample command:

curl "https://api.stackexchange.com/2.2/users/10348758/answers?page=1&pagesize=100&fromdate=1588291200&todate=1592179200&order=desc&sort=activity&site=stackoverflow&access_token=my-access-token&key=my-key" | gunzip | jq '[.items[] | select(.is_accepted == false)]'
  • In this case, jq '[.items[] | select(.is_accepted == false)]' is used for the retrieved values.
  • By this modification, the values with "is_accepted": false are retrieved.

Note:

  • In this modification, it supposes that your access token and key can be used for requesting to https://api.stackexchange.com/2.2/users/10348758/answers.

References:

halfer
  • 19,824
  • 17
  • 99
  • 186
Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • thank you for your answer! This worked perfectly :) Can you also tell me if there is a way to get the link of answers and questions also in the JSON response? – ESCoder Jun 27 '20 at 01:20
  • @Bhavya Thank you for replying. I'm glad your issue was resolved. About your new question, I think that the custom filter might be required to be used. [Ref](https://api.stackexchange.com/docs/filters) But in this case, your new question is different from your this question. So can you post it as new question? By this, it will help users including me think of the solution. If you can cooperate to resolve your new issue, I'm glad. – Tanaike Jun 27 '20 at 01:26
  • @Bhavya By the way, in the current retrieved values, `answer_id` and `question_id` are included. So using these values, you can also create the URLs like `https://stackoverflow.com/q/{question_id}` and `https://stackoverflow.com/a/{answer_id}`. – Tanaike Jun 27 '20 at 01:30
  • Thank you for replying. Yes, the ids are included, but I also want to get there link in the response itself. Anyways, I will try this out OR since it is a separate question, I will post it as a new one. – ESCoder Jun 27 '20 at 01:33
  • @Bhavya Thank you for your response. When you post it, I would like to also check it. – Tanaike Jun 27 '20 at 01:34
  • Yes definitely, as soon as I post this new question, I will ping you :) – ESCoder Jun 27 '20 at 01:35
  • Can you please go through this question also https://stackoverflow.com/q/62606821/10348758 – ESCoder Jun 27 '20 at 06:44