How to connect odoo with magento 2.2?
-
21-12-2020 - |
Question
I need connect odoo with magento 2.2, and I get some result but I got and 401 error when I try to call one service with my generated token. So far:
from suds.client import Client
url="https://myserver.com/soap/default?wsdl&services=integrationAdminTokenServiceV1"
client = Client(url)
result = client.service.integrationAdminTokenServiceV1CreateAdminAccessToken('user', 'pass')
That result store a token to do the authentication, like http://devdocs.magento.com/guides/v2.2/get-started/soap/soap-web-api-calls.html, but, when I try
msg = str('Bearer '+result)
header = {'Authorization': msg}
target_url = "https://myserver.com/soap?wsdl&services=customerCustomerRepositoryV1"
client = Client(target_url, headers=header)
I got Transport Error:
HTTP Error 401: Unauthorized.
Any suggestions?
Solution
import requests
import urllib
from requests_oauthlib import OAuth1
def _mage_call(self, credentials):
f = {
'searchCriteria[filter_groups][0][filters][0][field]':'created_at',
'searchCriteria[filter_groups][0][filters][0][value]':'2017-12-12',
'searchCriteria[filter_groups][0][filters][0][condition_type]':'gt',
'searchCriteria[filter_groups][1][filters][0][field]':'increment_id',
'searchCriteria[filter_groups][1][filters][0][value]':'000000001,000000002',
'searchCriteria[filter_groups][1][filters][0][condition_type]':'in'
}
method = 'orders?'+urllib.urlencode(f)
auth = OAuth1(credentials['consumer_key'], credentials['consumer_secret'],credentials['access_token'], credentials['access_token_secret'])
result = requests.get(credentials['url']+method, auth=auth, verify=False)
return result.text
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange