我需要使用API向联系人添加一个标记。
根据API V3文档(https://developers.activecampaign.com/reference#create-contact-tag),我正在使用活动的竞选资源,提出了一个POST请求。我还有其他请求,比如添加和获取联系人,以及以相同的方式添加和获取帐户。
但是,发出请求时,我只收到一个400坏的请求状态,包括错误没有标签id提供。我已经检查了标签id和联系人id。
我使用这个函数来填充联系人标签,我检查了,在发送时两者都被填充。
private void UpsertTag(GetAllTagsOutput output, string contactId, string tagvalue)
{
TagMeta tag = output.Tags.FirstOrDefault(c => c.Tag == tagvalue);
ContactTag contactTag = new ContactTag
{
Contact = contactId,
Tag = tag.Id
};
this.service.Upsert(contactTag);
}contacttag类如下所示:
[Api("contactTags")]
public class ContactTag : ActiveCampaignRef
{
/// <summary>
/// Contact ID
/// </summary>
public string Contact { get; set; }
/// <summary>
/// Tag ID
/// </summary>
public string Tag { get; set; }
}然后我用
public T Upsert<T>(T item, IDictionary<string, string> parameters = null) where T : ActiveCampaignRef
{
if (IsNestedObject(item))
{
return requestService.Post<T>(GetPath(item), item);
}
var responseValues = requestService.Post<Dictionary<string, object>>(GetPath(item), item, parameters);
return JsonConvert.DeserializeObject<T>(responseValues[GetItemName(item)].ToString());
}get路径确实返回预期路径https://youraccountname.api-us1.com/api/3/contactTags
最后我得到了一个职位
public TResponse Post<TResponse>(string path, object data, IDictionary<string, string> parameters = null)
{
return this.Send<TResponse>(path, "POST", data, parameters);
}
private TResponse Send<TResponse>(string path, string method, object data = null, IDictionary<string, string> parameters = null)
{
return JsonConvert.DeserializeObject<TResponse>(this.SendRequest(path, method, data, parameters));
}
private string SendRequest(string path, string method, object data = null, IDictionary<string, string> parameters = null)
{
var finalPath = path;
if (parameters != null && parameters.Any())
{
// Add parameters to the request
var queryString = string.Empty;
foreach (var param in parameters)
{
queryString = queryString + "&" + param.Key + "=" + param.Value;
}
finalPath += "?" + queryString;
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + finalPath);
request.Method = method;
request.Headers.Add("API-Token", apiKey);
AttachDataIfNecessary(request, data);
try
{
var webResponse = (HttpWebResponse)request.GetResponse();
using (Stream dataStream = webResponse.GetResponseStream())
{
StreamReader reader = new StreamReader(dataStream);
string response = reader.ReadToEnd();
return response;
}
}
catch (WebException e)
{
throw GetActiveCampaignException(e);
}
}方法: POST状态: BadRequest响应:{“错误”:{“标题”:“查询参数contactTag.tag的无效值”,“详细信息”:“没有提供标签id”,“源”:{“参数”:“contactTag.tag”}}‘
发布于 2022-02-24 15:48:02
因此,我遇到了这个问题(使用php),我花了很长时间才弄明白这一点,但对我来说,问题是API文档中有一个小错误,一开始我发布了
'body' => '{"contact":"1","tag":"2"}',
当所需的机构是:
'body' => '{"contactTag":{"contact":"1","tag":"20"}}',
我不确定这是否正是您的错误,因为您正在创建这个contactTag对象,但是我确实得到了完全相同的错误,对于我来说,使用第二个主体是有效的。
https://stackoverflow.com/questions/70576631
复制相似问题