I am trying to connect Magento 2 Integration system / Web APIs with ERPNext OAuth Client. Unfortunately I always have the error:
{“error”:“unsupported_grant_type”}
By using google, I found that most of this issues occur, because the Content-Type header of the request is empty. In this case, it’s true as well; but I can not imagine that there is a problem in Magento 2, neither in ERPNext.
After long time trial and error, I was hoping that someone might know how to configure it properly:
Before investigating more, I just wanted to be sure, that I am on the right track. Maybe I am misunderstanding something very basic and someone might lead me to the right direction.
@ci2016 What are your plans for this connector? We are working on this also but would rather not duplicate effort if you’re already further along. Can we contribute somehow?
There is a button which initiates a get request in browser. e.g. In this case there must be a button on Magento’s Screen for access frappe resource.
The response of this request is redirect to the specified redirect url in Oauth Client.
Code is sent to the specified url. (in this case it’ll be an endpoint on magento side)
This endpoint on magento server will take the code and request to get_token endpoint on frappe server. @ci2016 OAuth 2 Client’s Redirect URIs must be on magento.custom.work and not erp.custom.work
Response of this get_token endpoint is bearer token, which can be used to access resource on frappe server.
To complete “Login with” thing. Magento must call openid_profile endpoint with access token in header and get the details of the user. Use this user details to create or update user linked in magento.
If “login with” is not required, just use the access token to get resources from frappe server.
At the moment I was writing the post, I was trying to achieve a connection between Magento 2 and ERPNext. I assumed Magento 2 has OAuth2 (which it doesn’t) and that Magento 2 supports Webhooks (which it doesn’t as well).
My plan was to simply push all data which is coming into Magento 2, for example orders, products etc. to ERPNext (preferably as JSON) and save it to the right doctype.
Since Magento 2 doesn’t support OAuth 2 and doesn’t have Webhooks at all, I think the smartest way is just to pull all the data every hour by a custom app.
By the way: theres a community approach to bring webhooks to Magento 2, which uses Observers, but it doesn’t have a lot of contributors and it’s not very advanced in the moment. If you wan’t to have a closer look, heres the Github link.