Pieter
Pieter

Reputation: 389

Sendgrid only Finds Legacy Templates

I am setting up a SendGrid client for a project. When I try to access my Templates in SendGrid It only returns the legacy ones but totally ignores the transactional ones. I have not found any documentation concerning this specific problem online.

public async Task<Dictionary<string, string>> GetTemplateIdsByNameAsync()
    {
        //https://sendgrid.com/docs/API_Reference/Web_API_v3/Transactional_Templates/templates.html
        //My client is being autheticated succesfully in the GetSendGridClient function
        var client = GetSendGridClient();

        //This function should get all the templates connected to my SendGrid account but only finds the legacy ones
        var response = await client.RequestAsync(method: SendGrid.SendGridClient.Method.GET, urlPath:"templates");

        ThrowExceptionIfStatusIsNotOk(response);

        var content = await response.Body.ReadAsStringAsync();

        var anonymousTemplatesObject = new { Templates = new[] { new { Id = "", Name = "" } } };

        var templates = _genericJsonSerializer.DeserializeAnonymous(content, anonymousTemplatesObject);

        return templates.Templates.ToDictionary(x => x.Name, x => x.Id);
    }

I have been sitting on this problem for a good day now but have not found a solution

Upvotes: 1

Views: 514

Answers (1)

sdsykes
sdsykes

Reputation: 1256

Although SendGrid have not documented it properly yet, the correct API call syntax is https://api.sendgrid.com/v3/templates?generations=legacy,dynamic

So in this case you need to use https://api.sendgrid.com/v3/templates?generations=dynamic

See here for a little more background: https://github.com/sendgrid/sendgrid-csharp/issues/723

Upvotes: 2

Related Questions