I’m working on an add-in for another program that will allow posting some text to write.as. I’d like to include the ability to do so under a username in addition to anonymously.
From reading the API documentation, it seems clear enough how to get an access token. But a couple things are not.
Once a user token is received, are any posts made from that computer (IP?) automatically going to go under that authenticated user? I didn’t see anything in the API for posting that showed where a token would be included, which makes me think the answer is yes.
If that’s correct, does the token serve any purpose beyond logging out later?
Also, (again if the token doesn’t need to be included with a post), is it possible to later make an anonymous post without specifically logging the user out?
Is there any way via the API to select which blog (if the user has more than one) the post goes to? Or will it always go to the primary?
Once a token is received, it means that any posts made using that token goes under the authenticated user.
To use the token when creating a post, you can do one of two things.
- Include the token in the header of the request. It should look like so:
Authorization: Token 00000000-0000-0000-0000-000000000000
- If you are using an API Library like the one that is there for Go, you set the token using a library method that should look like this:
c = writeas.client()
After setting it you can call a create post method and the post should be under the authenticated user.
And you do have a way through the API to choose what blog to publish a post to. It is the “Publish a Collection Post” endpoint. Learn more about it here - the example in the link shows how the token works also.
What language are you writing the program in?
Please let me know if you need further clarification. Best of luck!
Thanks, that’s exactly what I needed to know!
As for the language, I’m using QML. More specifically, I’m writing an add-on for QOwnNotes that will allow submission of a note to Write.as directly (using
XMLHTTPRequest). Hopefully the admins don’t mind a bunch of dummy anonymous posts that I’ve needed to figure out how to get this to work…
Let us all know how this progresses. Sounds interesting!
Yes, please keep us updated!
As far as question #2 goes @CountFenring , the token can also be used for other actions on behalf of a user like creating and deleting collections (ie: blogs) along with updating and deleting particular posts that belong to a user’s account.
So, for example, if you wanted to create a script that would import your blog to Write.as, you could have the script create the collection and then create the posts that would go into that collection.
Great, thanks for the info.
That makes sense. I’m not sure how far I’ll take this as far as other functionality, but at the least I do want to be able to have it post to specific collections if applicable.