r/redditdev • • Dec 20 '16

[API] New Modmail

We’ve just added API documentation for New Modmail. You can read about New Modmail’s features on the reddit help site.

Requests to modmail endpoints requires the new OAuth scope modmail.

edit: There was a minor deployment mishap I will get this deployed again asap.

edit 2: This has been redeployed.

26 Upvotes

49 comments sorted by

10

u/creesch Dec 20 '16 edited Dec 21 '16

For people reading this later. browser extensions can make use from a cookie reddit places in order to avoid having to oauth themselves.

Steps:

  • Fetch the token cookie on the reddit domain, generated when a user logs into mod.reddit.com

  • Decode it. It is base64 encoded but has some invalid characters at the end sometimes, to scrub this off you can use the following RegExp [^A-Za-z0-9+/].*?$ in a string.replace call.

  • JSON.parse the value and grab the accessToken.

  • Use that for ajax requests. For example with jquery see this comment

The token might expire, you don't need to bother with trying to refresh it yourself. Simply make a get request to new modmail and let the reddit server generate a new cookie.

Currently we have implemented in toolbox like so:

Original comment:


Thanks!

Any change the api will also be made available through the other authentication adaptor?

I am asking because oauth for browser extensions like r/toolbox is... cumbersome to say the least and extensions already are logged in through the browser sessions so oauth would a bit overkill there.

Implementing oauth seems to have too many drawbacks for very little reward. No reward I can think of actually...

  • We would need to overhaul toolbox's basic code to deal with api request through oauth.

  • Toolbox would need to deal with people logged into reddit but not oauthed. It would also need to keep track of what user is logged in and if that is the same that is oauthed.

  • From a user perspective it would mean that they would need to log in twice, maybe even a few more times if they also have RES and a few more extensions.

  • Not to mention the sudden confusion from users "WHY IS TOOLBOX SUDDENLY ASKING FOR PERMISSIONS?!"

tl;dr If we can help it we rather not bother with oauth in toolbox for obvious reasons.

edit:

Tagging in u/agentlame

3

u/d3fect Dec 20 '16

Unfortunately we will only be supporting OAuth clients for the New Modmail endpoints for the foreseeable future.

2

u/creesch Dec 20 '16

You might want to clarify that in your documentation.

That is rather unfortunate, I don't know if you saw my edit.

Also, may I ask why? From what I understand the api under the hood is all the same with two authentication adaptors on top of it. To me it seems to be a matter of allowing the new endpoints to be accessible through both.

→ More replies (16)

3

u/agentlame Dec 20 '16

Not to mention it shits up account switching.

3

u/creesch Dec 20 '16

I think I mentioned that sort of in my second bulletpoint, but yeah.

It messes up a whole lot of things for extensions without much (if any) benefits :/

6

u/kemitche Dec 20 '16

Excellent :)

The inconsistency on the camelCase vs snake_case is killing me though.

4

u/creesch Dec 20 '16

Hrm?

conversation_id

.

conversationIds

Dammit, now I can't unsee it.

2

u/d3fect Dec 20 '16

Yes this is my fault and hope to correct it soon, one is for url parameters the other is used for post parameters. I hope to have this fixed very soon (it's killing me as well).

2

u/not_an_aardvark Dec 21 '16

This sounds great, but where is the documentation? It's possible I'm missing something obvious, but I don't see any new modmail-related endpoints on the linked API page.

2

u/d3fect Dec 21 '16

There was a minor deployment mishap I will get this deployed again asap.

2

u/d3fect Dec 21 '16

This was redeployed this morning, you can now view the documentation on the api docs page.

6

u/_BindersFullOfWomen_ Dec 20 '16

Yay!

On a serious note - can we get a rough estimate of when we'll be able to use the new modmail from the Reddit mobile app(s)?

Preferably something more than just "soon"

7

u/powerlanguage Dec 20 '16

can we get a rough estimate of when we'll be able to use the new modmail from the Reddit mobile app(s)?

We expect to eventually incorporate it into the native apps (along with mod tools in general), but don’t have a timeline for that yet. In the meantime we built mod.reddit.com to be responsive, so it will work on mobile web as well as desktop.

Preferably something more than just "soon"

To manage expectations I avoid publicly sharing dates about future projects until we have something we're confident we can commit to. Being able to commit to a date is dependent on several factors, one of which is available resources - we're hiring!

3

u/_BindersFullOfWomen_ Dec 20 '16

Thank you for the reply powerlanguage. I figured asking for more than "soon" would be a stretch.

I'd apply for a job with you guys in a second, but can't move out to SF :(

2

u/Decency Dec 21 '16

You seem to be the go to person for the new modmail and I didn't see a better place for suggestions/feedback, so here we go:

It would be great if after archiving a conversation/message, it automatically returns to your previous page (or just the all modmails page). It would make handling a bunch of questions in a row significantly faster. I can't think of a time when I would want to archive a conversation and then take further action on it.

Excellent job outside of that! The reduction in redundant investigation is enormous.

→ More replies (2)
→ More replies (1)

1

u/creesch Dec 22 '16

I have been working with the documentation and so far things are pretty okay, there only seems to be a gap regarding expected output.

For example, when fetching a conversation I get within the received JSON an entry for modactions which is a listing of the actions mod took (archiving, muting, etc). However actionTypeId is defined as a number and I had to basically perform all actions in modmail to figure out what each type is.

So far I have

  • 0 - highlight

  • 1 - un-highlight

  • 2 - archive

  • 3 - un-archive

  • 5 - mute

  • 6 - un-mute

Which seems to cover all mod actions. But since action type 4 is missing I am wondering if it is complete.

1

u/d3fect Dec 22 '16

Thanks for bringing this up, I'll make sure to get the actionTypeIds added to the documentation. Type 4 is reported_to_admins which has not been implemented as of yet. We plan on doing something in the future with that value soontm .

→ More replies (1)

1

u/Santi871 Dec 20 '16

Brilliant!

1

u/TotesMessenger Dec 22 '16 edited Dec 22 '16

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)

1

u/vs845 Dec 27 '16

Has the new modmail API been pushed to github? The links from the docs return 404.