Skip to content

Problem making a request to SendGrid API #912

Closed

Description

@edorguez

Issue Summary

I'm trying to make a GET request to the API in C# using the NuGet Package. The problem is when I try to make a GET request to "categories/stats" it throws an error message saying "start_date is required and should be a YYYY-MM-DD formatted date" even though I'm writting "start_date" to the query parameter like the documentation says. Here is my code.

string queryParams = @"{
                              'aggregated_by': 'day', 
                              'categories': '2586', 
                              'end_date': '2019-07-01',
                              'limit': 1,
                              'offset': 1, 
                              'start_date': '2019-03-01' 
                       }";

var response = await client.RequestAsync(method: SendGridClient.Method.GET, urlPath: "categories/stats", requestBody: queryParams)

Technical details:

Activity

  1. edorguez commented on Aug 2, 2019

    @edorguez
    Author

    Btw, I solved the issue without using the NuGet Package.

    var client = new RestClient("https://api.sendgrid.com/v3/categories/stats?aggregated_by=day&limit=10&categories=MyCategory&start_date=2019-06-06");
    var request = new RestRequest(Method.GET);
    request.AddHeader("authorization", "Bearer <<MY TOKEN>>");
    request.AddParameter("undefined", "{}", ParameterType.RequestBody);
    IRestResponse response = client.Execute(request);
    

    But I'm still confused about why the first solution didn't work in this case if I've previously used the same way to make a GET request to other urlPath.

  2. thinkingserious commented on Aug 21, 2019

    @thinkingserious
    Contributor

    Hello @edorguez,

    Thanks for reporting this and for providing a work around. We've added this issue to our backlog for further review.

    With best regards,

    Elmer

  3. childish-sambino commented on Jun 23, 2020

    @childish-sambino
    Contributor

    This is probably the issue in your code:

    requestBody: queryParams
    

    Working example here: https://github.com/sendgrid/sendgrid-csharp/blob/master/examples/categories/categories.cs#L37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions