2017-05-23 49 views
1

创建使用Mautic API的电子邮件文档是: https://developer.mautic.org/#create-email使用Mautic API时,如何在创建电子邮件时发送参数“列表”?

我不能创建一个没有指定参数列表的电子邮件。 的列出参数指定这样的:使用Python的后段ID

列表阵列阵列应该被添加到段电子邮件

如何通过HTTP发送的参数列表,以便Mautic API可以解决它吗?

这将创建类型为“模板”(默认)在Mautic的电子邮件......

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

但我需要的是创造型的“列表”的电子邮件。

对于这一点,它是强制性的,指定每个列表IDS。 列表是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>' 
}  

我尝试过很多办法......我总是得到errror:

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

回答

0

每您链接到API文档的修改版本,lists需求是:

段ID的数组,它应该被添加到该段电邮

但是,你是不是在列表中(阵)发送对lists值。相反,你应该尝试:

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

使用Python中的请求,我产生一个网址安全有效载荷串看起来像以列表ID传递到段电子邮件中剪断:

lists%5B%5D=7 

等号

lists[]=7 

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

为了与连接到它的段创建电子邮件的列表(段电子邮件)产生与邮差的帮助下,下面的代码:

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) 

看你的具体问题,我可以想像,你的代码应该是这样的(虽然我不熟悉你的蟒蛇LIB):

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

希望这有助于!

相关问题