{"id":2332,"date":"2014-09-14T19:12:41","date_gmt":"2014-09-14T15:12:41","guid":{"rendered":"http:\/\/nayarweb.com\/blog\/?p=2332"},"modified":"2014-09-14T19:15:04","modified_gmt":"2014-09-14T15:15:04","slug":"cookie-and-cookie-jars-with-rest-api","status":"publish","type":"post","link":"https:\/\/nayarweb.com\/blog\/2014\/cookie-and-cookie-jars-with-rest-api\/","title":{"rendered":"Cookie and Cookie Jars with REST API"},"content":{"rendered":"<p>Been playing with ERPNext a bit recently. Tried to test the REST API so as to learn how it works.<\/p>\n<p>In the <a href=\"https:\/\/frappe.io\/developers\/api\/rest_api\" target=\"_blank\">Frappe documentation<\/a>, it says to login like this:<\/p>\n<p><a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/09\/snapshot1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"712\" height=\"313\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/09\/snapshot1.png\" alt=\"snapshot1\" class=\"aligncenter size-full wp-image-2334\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/09\/snapshot1.png 712w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/09\/snapshot1-300x131.png 300w\" sizes=\"auto, (max-width: 712px) 100vw, 712px\" \/><\/a><\/p>\n<p>Tried the following code in my terminal and it worked<\/p>\n<p><code>$ curl --data \"usr=Administrator&pwd=admin\" http:\/\/localhost:8000\/api\/method\/login<\/code><\/p>\n<p>However the API to test whether the user has been logged in was not working<\/p>\n<p><code>$ curl http:\/\/localhost:8000\/api\/method\/frappe.auth.get_logged_user<\/code><\/p>\n<p>It would NOT work :-\/<\/p>\n<p>If i would paste the URL in my web browser, it would recognize that i was logged in. <\/p>\n<p>I realized cookies are being used. To do it from the command line, all i had to do was create a cookie jar and later fetch the cookie from the jar \ud83d\ude09<\/p>\n<p><code>$ curl --data \"usr=Administrator&pwd=admin\" http:\/\/localhost:8000\/api\/method\/login --cookie-jar lol<\/p>\n<p>$ curl http:\/\/localhost:8000\/api\/method\/frappe.auth.get_logged_user --cookie lol<\/code><\/p>\n<p>It would finally recognize me now. \ud83d\ude00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Been playing with ERPNext a bit recently. Tried to test the REST API so as to learn how it works. In the Frappe documentation, it says to login like this: Tried the following code in my terminal and it worked $ curl &#8211;data &#8220;usr=Administrator&#038;pwd=admin&#8221; http:\/\/localhost:8000\/api\/method\/login However the API to test whether the user has been &hellip; <a href=\"https:\/\/nayarweb.com\/blog\/2014\/cookie-and-cookie-jars-with-rest-api\/\" class=\"continue-reading\">Continue reading <span class=\"screen-reader-text\">Cookie and Cookie Jars with REST API<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[193,192],"class_list":["post-2332","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-frappe-io","tag-rest"],"_links":{"self":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/comments?post=2332"}],"version-history":[{"count":5,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2332\/revisions"}],"predecessor-version":[{"id":2338,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2332\/revisions\/2338"}],"wp:attachment":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/media?parent=2332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/categories?post=2332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/tags?post=2332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}