9

I'm working on extending wishlist functionality to Magento's REST api. It would be nice to access the customer's session. Does Magento have any support for accessing the customer's session via REST?

  • Why do you need session access? The wishlist items are store in the db and have a reference to the customer id. ..Or maybe I'm missing something – Marius Aug 30 '13 at 7:08
  • Because I don't have the customer id. – Ryre Aug 30 '13 at 15:22
  • 2
    Ok...seams fair...sorry for my ignorance :) – Marius Aug 30 '13 at 15:30
  • No worries! My question was brief, so a little explanation is probably in order. – Ryre Aug 30 '13 at 16:06
  • As I read in the Magento REST API Documentation there is no access to the session via REST. Did you think about using oAuth? – Anna Völkl Sep 4 '13 at 9:43
5
+50

As mentioned in my comments above, I would recommend to provide a user login with oAuth to gain access to the customerID. To anwer your question: No, it's not possible to access the customer session.

The flow can be as follows:

  1. User accesses a 3rd party website where you want to provide the wishlist functionality
  2. User request wishlist/wishlist functionality (by adding a new item to wishlist, showing his wishlist etc.)
  3. User logs in via oAuth in your magento shop
  4. Retrieve customer ID from oAuth
  5. Proceed with your wishlist functionality

For the user Authorization, I recommend you follow the sections "Getting an Unauthorized Request Token" and "User Authorization" on this page.

| improve this answer | |
  • Your answer was the first to offer a workable solution! – Ryre Sep 12 '13 at 2:29
  • What is the accepted way of getting customer ID from oAuth? I don't see such functionality anywhere in their docs. – Stepan Mazurov Dec 19 '13 at 5:38
  • I have figured it out. For anyone else having the same issue, ensure that your "customer" role has permissions to access the api – Stepan Mazurov Dec 19 '13 at 18:18
  • Hello @Anna Völkl , How i get customer id in magento REST api ? Because when i pass customer token in Header i need customer id which customer token is belonged to that specific customer token in magento 2 – Aditya Shah Jul 26 '18 at 10:44
  • My products API returns products, if i try with customer i am getting error, my url : 192.168.1.65/anusthana/api/rest/customers error : snag.gy/0jbhTr.jpg can u help me @Anna – zus Oct 23 '18 at 10:55
6

No.

The customer session is tied against the frontend cookie the browsing customer has. If you are using file based sessions these would be stored under var/sessions/ - if you are using the database as session storage this would be stored in core_session.

In any case to be able to access it you would need to know the session_id from the customer which by design should only be between browser and server. *1)

A better approach, as suggested in the comments above, would be to figure out what information you do have available for the customer (customer_id, email address) and then access the wishlist via that.

One further thing to keep in mind is that the session you have established to communicate to the API is separate to the session a customer has.

Overall I feel you would get a more actionable answer if you posted what it is you are trying to achieve with the wishlist stating your current constraints.

*1) you might be able to read the currently used cookie session and save it to the database for further processing, but you will again need some other information to tie this back to the logic you are currently trying to implement, so I do not see any use for it here.

| improve this answer | |
  • thanks for the great answer. My end-goal is to access customer data via REST that the customer sees when logging into the front-end: order history, saved addresses, etc. – Ryre Sep 6 '13 at 19:50
  • Some more context would certainly help. What application is making these requests? My guess here is that you have a non-Magento website in which you want to display Magento data but this is not quite clear from your question and could be something else completely. The OAuth suggestions involve actions the customer would need to do. Other approaches include sharing the session between the two systems (for example take a look at the various wordpress integrations). – Kristof at Fooman Sep 8 '13 at 22:40
  • Your guess is pretty close! I'm helping to extend basic REST services for an iphone app. The front-end oauth solves the problem I'm having; sorry for not asking a clearer question. – Ryre Sep 9 '13 at 21:35
1

I think what you're looking for is a mix of the REST API and Magento's OAuth. With OAuth the frontend user can login onto the Magento environment giving your (3th party) application and access to his customer data like order history.

As far as I know this is as close as you can get to the customer session using the API.

Check out this Magento documentation on the subject and also this nice article by Inchoo

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.