ActiveCampaign Forum

Trying to add a user to a tag not working... Ruby


#1

Here is my code… I create a contact
new_client = ‘https://jewsforjudaism.api-us1.com/api/3/contacts
new_tag = ‘https://jewsforjudaism.api-us1.com/api/3/contatTags

headers = {
“Api-token” => api_key,
“Content-Type” => “application/json”,
“Accept” => “application/json”
}

user = HTTParty.post(new_client, headers: headers, body: query.to_json)
user_id = user[“contact”][“id”]

tag = {
“contactTag”: {
“contact”: user_id,
“tag”: “98”
}
}

user = HTTParty.post(new_tag, headers: headers, body: tag.to_json)

Error I get
=> #<HTTParty::Response:0x7ff91b4806e0 parsed_response=nil, @response=#<Net::HTTPNotFound 404 Not Found readbody=true>, @headers={“date”=>[“Wed, 05 Jun 2019 17:35:23 GMT”], “content-type”=>[“application/json”], “content-length”=>[“0”], “connection”=>[“close”], “set-cookie”=>["__cfduid=d675eb3935843fd503c7169b1ab5758191559756123; expires=Thu, 04-Jun-20 17:35:23 GMT; path=/; domain=.api-us1.com; HttpOnly", “PHPSESSID=vffmkia61anma5bh0pvc8kc1m5; path=/; HttpOnly”, “em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=.foobar.api-us1.com”, “em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=.jewsforjudaism.api-us1.com”, “em_acp_globalauth_cookie=769fef5b-2916-40d8-aeda-e6def821c83b; path=/; domain=.jewsforjudaism.api-us1.com; secure; httponly”], “expires”=>[“Thu, 19 Nov 1981 08:52:00 GMT”], “cache-control”=>[“no-store, no-cache, must-revalidate, post-check=0, pre-check=0”], “pragma”=>[“no-cache”], “expect-ct”=>[“max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct””], “server”=>[“cloudflare”], “cf-ray”=>[“4e23e71aca34d27e-DFW”]}>

What am I doing wrong? It correctly adds the user but when I try to insert a tag within the user it fails… and the TagId exists…


#2

It looks as though you have a type in the new_tag url:
new_tag = ‘https://jewsforjudaism.api-us1.com/api/3/contactTags’

(the c is missing in contactTags

I hope this helps