batchblue / batchbook-api

Official API documentation for Batchbook
http://batchbook.com
12 stars 2 forks source link

Problem with tags removing #15

Closed Bonias closed 8 years ago

Bonias commented 9 years ago

I have a problem with tags removing. I tried with (as documentation says):

"person":{
  "tags":[
    {
      "name":"One",
      "_destroy":"1"
    }
  ]
}

but tags are not removed. I tried also:

"person":{
  "tags":[
    {
      "id":2,
      "_destroy":"1"
    }
  ]
}

and:

"person":{
  "tags":[
    {
      "id":2,
      "name":"One",
      "_destroy":"1"
    }
  ]
}

I'm able to destroy email without a problem, but tags are not removed.

Here is curl command:

$ curl -i -H "Content-Type: application/json" -X PUT -d '{"person":{"tags":[{"name":"One","_destroy":"1"}]}}' -# https://bonias.batchbook.com/api/v1/people/1594.json?auth_token=xxx | head -n 1
######################################################################## 100,0%
HTTP/1.1 200 OK

$ curl https://bonias.batchbook.com/api/v1/people/1594.json?auth_token=xxx
{"person":{"id":1594,"about":null,"emails":[],"phones":[],"websites":[],"addresses":[],"tags":[{"id":2,"name":"One"}],"comments":[],"cf_records":[],"created_at":"2015-09-22T10:32:10-04:00","updated_at":"2015-09-22T10:39:00-04:00","prefix":null,"first_name":"TestContact remove tag","middle_name":null,"last_name":null,"champion":false,"company_affiliations":[]}}
challengee commented 8 years ago

@randerson @erickrause we're still having this problem, would you mind taking a look at that? Thanks!

randerson commented 8 years ago

I've taken a look at your curl's above.

What are you trying to do with this one:

$ curl -i -H "Content-Type: application/json" -X PUT -d '{"person":{"tags":[{"name":"One","_destroy":"1"}]}}' -# https://bonias.batchbook.com/api/v1/people/1594.json?auth_token=xxx | head -n 1

Are you trying to remove the tag from a contact or delete the tag in its entirety?

Bonias commented 8 years ago

I'm trying remove tag from contact. I want contact to be equal:

{"person":{"id":1594,"about":null,"emails":[],"phones":[],"websites":[],"addresses":[],"tags":[],"comments":[],"cf_records":[],"created_at":"2015-09-22T10:32:10-04:00","updated_at":"2015-09-22T10:39:00-04:00","prefix":null,"first_name":"TestContact remove tag","middle_name":null,"last_name":null,"champion":false,"company_affiliations":[]}}

I think I do the same what is showed at xml example at https://github.com/batchblue/batchbook-api/blob/master/sections/people.md:

<tags type="array">
  <tag>
    <name>awesome</name>
  </tag>
  <tag>
    <name>not awesome</name>
    <_destroy type="integer">1</_destroy>
  </tag>
</tags>

Unfortunately, there is no example using json format.

m0dd3r commented 8 years ago

@Bonias @challengee looks like we've got an odd bug in tags. We should be checking for pretty much any truthy value on that _destroy flag but instead we're explicitly checking for "true" or a boolean true. We should have a full fix out later in the week. In the meantime you should be able to use "_destroy": "true" instead of 1 and it will work. Sorry about the confusion and thanks for the bug report.

randerson commented 8 years ago

Here's a sample for Contact ID 17 in your account (just add your auth and subdomain)

curl -vH "Content-Type: application/json" -X PUT -d '{                                                                                       
    "person": {                                                                                                                                
        "tags": [                                                                                                                              
            {                                                                                                                                  
                "_destroy":"true",                                                                                                                
                "name":"bbstaffer"                                                                                                             
            }                                                                                                                                  
        ]                                                                                                                                      
    }                                                                                                                                          
}' -# https://subdomain.batchbook.com/api/v1/people/17.json?auth_token=authtoken
Bonias commented 8 years ago

It is working with "_destroy": "true". Thanks.