代码之家  ›  专栏  ›  技术社区  ›  Manoj Goel

正在检索SendGrid事务模板列表

  •  0
  • Manoj Goel  · 技术社区  · 7 年前

    {
      "templates": []
    }
    

    猜猜怎么回事?

    0 回复  |  直到 7 年前
        1
  •  3
  •   Andrey Stukalin    7 年前

    猜猜怎么回事?

    当我打开devtools并看到它们是如何从UI请求自己的API时,我也解决了这个问题。长话短说——一个人必须通过额外的考试 generations=dynamic 查询参数。以下是我使用的C代码:

                var client = new SendGridClient("key");
                var response = await client.RequestAsync(
                    SendGridClient.Method.GET, 
                    urlPath: "/templates",
                    queryParams: "{\"generations\": \"dynamic\"}");
    
        2
  •  1
  •   Santo    6 年前

    使用Api 7.3.0 PHP

    require("../../sendgrid-php.php"); 
    $apiKey = getenv('SENDGRID_API_KEY');
    $sg = new \SendGrid($apiKey);
    
    #Comma-delimited list specifying which generations of templates to return. Options are legacy, dynamic or legacy,dynamic
        $query_params = json_decode('{"generations": "legacy,dynamic"}');
        try {
            #$response = $sg->client->templates()->get();
            $response = $sg->client->templates()->get(null, $query_params);
    
            echo $response->body();
            exit;
        } catch (Exception $e) {
            echo '{"error":"Caught exception: '. $e->getMessage().'"}';
    
        }
    
    推荐文章