Micheal Bingham
Micheal Bingham

Reputation: 31

Reddit API Add Friend Endpoint /api/friend

Whenever I attempt to make a PUT Request to Reddit API in order to add a friend, it fails and claims a JSON Parse Error 'JSON_PARSE_ERROR'. Nothing I do is working. Here is how I form the request.

   Endpoint: /api/v1/me/friends/username
>>> Endpoint URL: PUT https://oauth.reddit.com/api/v1/me/friends/micheal 
Authorization: Bearer <Access_Token> 
// The response given: 
{"fields": ["json"], "explanation": "unable to parse JSON data", "reason": "JSON_PARSE_ERROR"}

I have also tried the /api/friend/username endpoint and nothing works.

Upvotes: 0

Views: 239

Answers (1)

ScotchyScotchScotch
ScotchyScotchScotch

Reputation: 21

I had exactly the same problem, and your question led me to the solution.

The endpoint is expecting a json payload ACTUALLY NAMED "json." I'm not sure what language you're using, this is what it looks like in Node:

        var options = {
            url: 'https://oauth.reddit.com/api/v1/me/friends/mynewfriend',
            headers: {
                'User-Agent': 'Appname/1.0 by username',
                'Authorization': "bearer " + <Access_Token>
            },
            json: {
                'name': 'mynewfriend',
                'notes': 'whatever notes you want to put',
                 }
        };

        request.put(options, function(error, response, body) {
            blah blah blah
         }

the json itself is described in https://www.reddit.com/dev/api/#PUT_api_v1_me_friends_{username}

Upvotes: 2

Related Questions