gpt4 book ai didi

python - 使用 Mautic API,如何在创建电子邮件时发送参数 "lists"?

转载 作者:太空宇宙 更新时间:2023-11-04 02:50:01 25 4
gpt4 key购买 nike

使用 Mautic API 创建电子邮件的文档是: https://developer.mautic.org/#create-email

如果不指定参数 lists,我无法创建电子邮件。lists 参数指定如下:

列出应添加到分段电子邮件的分段 ID 数组

如何使用 Python 通过 HTTP post 发送参数列表,以便 Mautic API 可以理解它?

这会在 Mautic 中创建类型为"template"(默认)的电子邮件...

emailData = {    
'name': 'Email-teste',
'subject': 'Assunto teste',
'isPublished': '1',
'language': 'pt_BR',`enter code here`
'customHtml' : '<strong>html do email<strong>'
}

但我需要的是创建一个“list”类型的电子邮件。

为此,必须指定每个列表 ID。列表是 Mautic 中的片段....我有一个 ID 为 7 的片段!

如何使用 POST(Python 请求)将分段 ID 发送到 Mautic API?

emailData = {    
'name': 'Email-teste',
'subject': 'Assunto teste',
'emailType': 'list',
'lists': '7',
'isPublished': '1',
'language': 'pt_BR',
'customHtml' : '<strong>html do email<strong>'
}

我尝试了很多方法......但我总是得到错误:

u'errors': [{u'code': 400,
u'details': {u'lists': [u'This value is not valid.']},
u'message': u'lists: This value is not valid.'}]}

我确定我有一个 ID 为 7 的分割,正如我在 Mautic 界面中看到的那样。

我正在使用 https://github.com/divio/python-mautic 的修改版本

最佳答案

使用 Python 中的请求,我生成了一个 url 安全的 Payload 字符串,看起来像下面的片段,以便将列表 ID 传递给分段电子邮件:

lists%5B%5D=7

等于

lists[]=7

用纯文字。所以你必须把 [] 直接放在键名后面。

为了在 Postman 的帮助下将电子邮件创建为列表(电子邮件段)并附加了一个段,生成了以下代码:

import requests

url = "https://yourmauticUrl"

payload = "customHtml=%3Ch1%3EHello%20World%3C%2Fh1%3E&name=helloworld&emailType=list&lists%5B%5D=7"
headers = {
'authorization': "your basic auth string",
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache"
}

response = requests.request("PATCH", url, data=payload, headers=headers)

print(response.text)

看看你的具体问题,我可以想象你的代码应该是这样的(虽然我不熟悉你的 python 库):

emailData = {    
'name': 'Email-teste',
'subject': 'Assunto teste',
'emailType': 'list',
'lists[]': '7',
'isPublished': '1',
'language': 'pt_BR',
'customHtml' : '<strong>html do email<strong>'
}

希望这对您有所帮助!

关于python - 使用 Mautic API,如何在创建电子邮件时发送参数 "lists"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44145990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com