2

I've been trying to get this to work for the past 4 hours with no luck, so here's the problem:

I have this class:

class Bitly:

  def __init__(self, api_token):
    self.apiToken = api_token
    self.header = {'Content-Type':'application/json',
                   'Authorization' : 'Bearer {}'.format(self.apiToken)
                  }

  def shorten(self, longURL):
    payload = {"long_url": longURL}
    url = "https://api-ssl.bitly.com/v4/shorten"
    return requests.post(url, headers=self.header, data=payload)

that, after being initialized with a valid token, is supposed to return the response JSON with the shortened link inside when calling the shorten method. Instead i keep getting this response:

{"message":"UNPROCESSABLE_ENTITY","resource":"bitlinks","description":"The JSON value provided is invalid."}

And i can't figure out what i'm doing wrong with the payload for it to give me this message. I'm sure it's a stupid error but i'm pretty new to this, so have mercy.

SudoOmbro
  • 51
  • 6

1 Answers1

3

Nevermind, i solved it, here's the solution for future reference: instead of using

data=payload

use

json=payload

Yes, it was that simple.

SudoOmbro
  • 51
  • 6