Yeah, the API just flips a switch on the post id you pass in. So you can call it and if the post is already published it'll unpublish it and vice versa.