title: Deleting all rows in dataset with SODA API
body: <p>I'm trying to programmatically delete all the rows in a Socrata dataset, using the SODA API. I don't want to delete the dataset itself, because then I'd have lots of work to reconstruct it. It's also very slow to do this for thousands of rows.</p>
  
  <p>Previously, I iterated slowly over each row, deleting each, until <a href="https://twitter.com/thomaslevine/status/545040433177321473" rel="nofollow noreferrer">someone on Twitter</a>, suggested doing an Upsert with no rows. I believe that I implemented this and it worked, but now it doesn't.</p>
  
  <p>Here's the relevant bit of code:</p>
  
  <pre><code>headers = {'X-App-Token': config.app_token}
  headers['Content-Type'] = 'application/json'
  
  r = requests.put(config.dataset + '.json', data='[ ]', headers=headers, auth=config.auth)
  print r.status_code, r.text
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>200 {
    "By RowIdentifier" : 0,
    "Rows Updated" : 0,
    "Rows Deleted" : 0,
    "Rows Created" : 0,
    "Errors" : 0,
    "By SID" : 0
  }
  </code></pre>
  
  <p>(So I think it's safe to say that the problem is not to do with authentication, authorisation, etc? My other functions to upsert rows work fine, so it's also not a problem with a wrong dataset URL or anything.)</p>
  
  <p>I also query the number of rows before and afterwards, and there is no change. Still thousands of rows.</p>
  
  <p>As far as I can tell, I'm following the API document for <a href="http://dev.socrata.com/publishers/replace.html" rel="nofollow noreferrer">Replacing rows in bulk</a>.</p>
  
  <p>The only thing I can think of is that due to a bug, I have multiple rows with the same rowid.</p>
  
  <p>EDIT</p>
  
  <p>Here are some duplicate row identifiers:</p>
  
  <p><img src="https://i.stack.imgur.com/El9SY.png" alt="enter image description here"></p>
  
  <p><code>rowid</code> is definitely set as a row identifier:</p>
  
  <p><img src="https://i.stack.imgur.com/MO3QR.png" alt="enter image description here"></p>
  
  <p>Now given that row identifiers are supposed to "<a href="http://dev.socrata.com/docs/row-identifiers.html" rel="nofollow noreferrer">essentially act the same way as primary keys</a>", I'm starting to wonder if this is a bug, or something has gone horribly wrong? The publishing code looks like this:</p>
  
  <pre><code>def publishDataset(rows):
    r = requests.post(config.dataset, data=simplejson.dumps(rows), headers = headers, auth=config.auth)
    j = r.json()
    print
    if r.status_code != 200:
      raise RuntimeError ( "%d Socrata error: %s" % (r.status_code, j['message']))
    return j
  </code></pre>
  
  <p>Full code here: <a href="https://github.com/stevage/meshlium-soda" rel="nofollow noreferrer">https://github.com/stevage/meshlium-soda</a></p>