asp.net-coresendgridsendgrid-api-v3sendgrid-templates

How do you retrieve a list of of transactional templates from SendGrid?


What is the correct usage for retrieving a list of transactional templates from the SendGrid API, the documentation doesn't seem correct.

https://docs.sendgrid.com/api-reference/transactional-templates/retrieve-paged-transactional-templates

var response = await client.RequestAsync(
    method: SendGridClient.Method.GET,
    urlPath: "v3/templates,
    queryParams: queryParams
);

The above documentation states to call the v3/templates API endpoint to retrieve a list of transactional templates. But I'm receiving a NotFound response when calling it. Changing the urlPath to templates provides a Forbidden response. I know the API key I'm using is correct because I can send emails with the client.


Solution

  • Twilio SendGrid developer evangelist here.

    I had a quick look through the C# library and it seems that it does put the v3 into the URL itself. So the example in the docs may well be wrong and I've alerted the team to this.

    So, when you change the urlPath to just "templates" you then got a Forbidden error. With SendGrid, API keys can be scoped to just certain actions within the API, so being able to send an email with an API key does not imply that key also has the permissions to read templates. I would try creating a new API key that definitely has permission to read templates and see if your code works.