简体   繁体   English

使用 postman 在 sendgrid v3 正文中发送动态变量

[英]Sending dynamic variables in sendgrid v3 body using postman

I am trying to send the emails via Sendgrid using v3 API using postman, I have created 3 separate variables in 3 different requests, I want to pass all those 3 variables in a single mail, for that I have used below sendgrid https://api.sendgrid.com/v3/mail/send我正在尝试使用 v3 API 使用 postman 通过 Sendgrid 发送电子邮件,我在 3 个不同的请求中创建了 3 个单独的变量,我想在一封邮件中传递所有这 3 个变量,因为我在下面使用了 sendgrid https://api.sendgrid.com/v3/mail/send
with below body身体下方

{
  "personalizations": [
    {
      "to": [
        {
          "email": "testing@test.com",
          "name": "API Testing"
        }
      ],
      "subject": "API testing successful"
    }
  ],
  "from": {
    "email": "noreply@testApi.com",
    "name": "API Testing"
  },
  "content": [
    {
      "type": "text/plain",
      "value": "{{variable1}}"  //In variable1 has a dynamic values
    }
  ]
}

but the above format sending the mail body as {{Variable1}}, can someone help me on this?但是上述格式将邮件正文发送为 {{Variable1}},有人可以帮我吗?

From what I understand of the question you want to send multiple requests with different values.根据我对您要发送具有不同值的多个请求的问题的理解。

Say, GET to https://google.com/q={{search}} and you have multiple search queries, (dog, chess, marvel, stackoverflow)说,GET 到https://google.com/q={{search}}并且你有多个搜索查询,(狗,国际象棋,奇迹,stackoverflow)

  • Create a collection in postman在邮递员中创建一个集合
  • Add a GET request to https://google.com/q={{search}} with necessary headers and hit Savehttps://google.com/q={{search}}添加一个带有必要标题的 GET 请求,然后点击Save
  • Create a CSV file with the header search and all search values under it使用标题search及其下的所有搜索值创建一个 CSV 文件
  • Hit the run button for the newly created collection点击新创建的集合的运行按钮
  • Set the Iterations field to the number of queries you have.Iterations字段设置为您拥有的查询数。 In this example it is 4在这个例子中它是 4
  • Look for the field Data , select the created CSV file查找字段Data ,选择创建的 CSV 文件
  • Ensure the data is correctly being picked up by hitting the Preview button通过点击Preview按钮确保正确获取数据
  • Hit Run test点击Run test
  • You can view the output in the Postman Console您可以在Postman Console查看输出

邮递员

To open Postman Console Head to View in the application menu, and click on "Show Postman Console" or use the keyboard shortcut (CMD/CTRL + ALT + C) to open. Head to View in the application menu, and click on "Show Postman Console" or use the keyboard shortcut (CMD/CTRL + ALT + C) to open.打开 Postman Console Head to View in the application menu, and click on "Show Postman Console" or use the keyboard shortcut (CMD/CTRL + ALT + C) to open.

For handlebar {{ variable_value }} substitutions in dynamic HTML templates, u need to pass the variable value as JSON structure with the key as "dynamic_template_data" as part of personalizations.对于动态 HTML 模板中的车把 {{ variable_value }} 替换,您需要将变量值作为 JSON 结构传递,并将键作为“dynamic_template_data”作为个性化的一部分。 U also need to pass the (API Key) Authorization as "Authorization: and Value as "Bearer ". In the Request Body pass the personalizations object. U 还需要将(API 密钥)授权传递为“授权:”并将值传递为“承载”。在请求正文中传递个性化 object。

{
"personalizations": [
    {
        "to": [
            {
                "email": "ron@***",
            }
        ],
        "dynamic_template_data": {
            "<variable_name>": <variable_value>
        }
    }
],
"from": {
    "email": "development@crosspaymt.com",
    "name": "Development Team"
},
"content": [
    {
        "type": "text/html",
        "value": "replace body with template content"
    }
],
"template_id": "******"

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM