odooasana-apiasana-connect

how to connect odoo with asana?


I want to connect my odoo with asana project. but it display HTTPError: HTTP Error 400: Bad Requesterror.

def execute(self, cr, uid, ids, context=None):
    params = {
        'client_id': '142025919&',
        'client_secret': '9691f60a6ca68&',
        'redirect_uri': 'urn:ief:wg:oauth:2.0:oob&',
        'state' :'somerandmstate'
    }
    headers = {"Content-type": "application/x-www-form-urlencoded"}
    req = urllib2.Request('https://app.asana.com/-/oauth_authorize%s?'%params)

    _logger.info(req)
    content = urllib2.urlopen(req, timeout=TIMEOUT).read()

Solution

  • I have a couple of recommendations for you:

    1. If you want to connect to the Asana API using Python, I highly recommend our client library.
    2. The page you are trying to load is intended for human use. Your app should direct a human to that page in a browser. They will get back a token that can be pasted into your application. See our OAuth documentation for more details.
    3. If you do decide to continue using this approach, there are a couple of things you need to do to fix your request to work in urllib2. Firstly, your query parameters should come after the question mark. Secondly you need to URL encode them using urllib.urlencode (and then you don't need to include the &s in the params dictionary). For example

      params = urllib.urlencode({
          'client_id': 'someID',
          'client_secret': 'someSecret',
          'redirect_uri': 'urn:ief:wg:oauth:2.0:oob',
          'state': 'somerandmstate'
      })
      req = urllib2.Request('https://app.asana.com/-/oauth_authorize?%s'%params)