0

I am successfully pulling back all issues on a given repo from GitHub, however, now I'm trying to utilize the 'since' parameter discussed in the link below to restrict the results and am having a very hard time. According to Mozilla, the parameters aren't even being sent.

GitHub Documation: https://developer.github.com/v3/issues/

function getIssues(callback) {
    var owner = $('#owner').val();
    var repo = $('#repo').val();
    $scope.owner = owner;
    $scope.repo = repo;

    var urlBase = 'https://api.github.com/';
    var urlUser   = urlBase + 'users/' + owner;
    var urlUserRepos  = urlUser + '/repos';

    var urlRepoIssues = urlBase + 'repos/' + owner + '/' + repo + '/issues';

    var ownerInput = angular.element(document.querySelector('#owner'));
    var repoInput = angular.element(document.querySelector('#repo'));
    var sinceInput = angular.element(document.querySelector('#since'));
    var errorFeedback = angular.element(document.querySelector('#errorFeedback'));
    var sinceDate = sinceInput.val();
    var tempDate = '2018-09-17T23:27:31Z';

    $http({
        method: 'GET',
        url: urlRepoIssues,
        headers: {'Content-Type': 'application/json'},
        data: { 'since': tempDate }
    }).then(
        //Success
        function(response) {
            ownerInput.addClass('is-valid').removeClass('is-invalid');
            repoInput.addClass('is-valid').removeClass('is-invalid');
            errorFeedback.html('');

            var data = response.data;
            callback(data);
        },
        //Fail
        function(response) {
            ownerInput.addClass('is-invalid').removeClass('is-valid');
            repoInput.addClass('is-invalid').removeClass('is-valid');
            errorFeedback.html('The Owner or Repo is incorrect.');

            var data = [];
            callback(data);
        }
    );
};
R. Richards
  • 24,603
  • 10
  • 64
  • 64
gunslingor
  • 1,358
  • 12
  • 34
  • HTTP GET requests don't have a request body, so of course the data isn't going to be sent. BTW using [callbacks from promise `.then` methods is an anti-pattern](https://stackoverflow.com/questions/35660881/why-are-callbacks-from-promise-then-methods-an-anti-pattern). – georgeawg Sep 17 '18 at 23:00

1 Answers1

0

data doesn't work with GET, only PUT, but params does work with GET. Thus, the following works:

$http({
  method: 'GET',
  url: urlRepoIssues,
  params: { 'since': sinceDate }
}) 
.
.
.

Additionally note how the date should be formated:

var sinceDate = new Date(sinceInput.val()).toISOString();
gunslingor
  • 1,358
  • 12
  • 34
  • It is erroneous to say that `data` is only sent with PUT operations. What about POST and DELETE operations? – georgeawg Sep 17 '18 at 23:05