{"id":3290,"date":"2022-07-13T12:37:45","date_gmt":"2022-07-13T12:37:45","guid":{"rendered":"https:\/\/www.cynoinfotech.com\/?p=3290"},"modified":"2022-07-13T12:44:53","modified_gmt":"2022-07-13T12:44:53","slug":"how-to-get-customer-data-by-id-magneto-2","status":"publish","type":"post","link":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/","title":{"rendered":"How to get customer data by id in Magneto 2"},"content":{"rendered":"<p>in this blog, we are going to how to get customer data by id using API repository and\u00a0 Factory Method<\/p>\n<p>There are two ways to get customer data that you can use. You can also get its product data through customer data.<\/p>\n<p><strong>\u21d2 Using API Repository to Get Customer Data:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">protected $_customerRepositoryInterface;\n\npublic function __construct(\n    \\Magento\\Customer\\Api\\CustomerRepositoryInterface $_customerRepositoryInterface,\n) {\n    $this-&gt;_customerRepositoryInterface = $_customerRepositoryInterface;\n}\n$_customerId = 12;\n$_customer = $this-&gt;_customerRepositoryInterface-&gt;getById($_customerId);\n\n  $_customerFirstName = $_customer-&gt;getFirstName();\n\/\/$customerData = $_customer-&gt;getData();\n<\/pre>\n<p><strong>\u21d2 Using Factory Method to Get Customer Data:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">protected $_customer; \n\n public function __construct(\n \n \\Magento\\Customer\\Model\\Customer $_customer\n\n ) {\n $this-&gt;_customer = $_customer;\n }\n\n public function getCustomerData()\n {\n   $_customerId=22;\n   $_customer = $this-&gt;_customer-&gt;create()-&gt;load($_customerId);\n   \/\/$customerData = $_customer-&gt;getData();\n  return $_customer;\n }\n}\n<\/pre>\n<p>\u21d2 <strong>Call Phtml File:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">$customerId = 1; \/\/pass dynamic customer id\n$Customer = $block-&gt;getCustomerData($customerId);\necho $Customer -&gt;getFirstname(); \/\/ result customer first name\necho $Customer -&gt;getEmail(); \/\/ result as customer email \necho $Customer -&gt;getLastname(); \/\/ customerr lastname\n<\/pre>\n<h3>\u21d2 Using Object Manager:<\/h3>\n<pre class=\"lang:default decode:true \">$customerId=1;\n$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n$customerData = $objectManager-&gt;create('Magento\\Customer\\Model\\Customer')-&gt;load($customerId);\n<\/pre>\n<p>use this code and nicely get\u00a0 Customer Data. if you have any questions put them in\u00a0 below comment section<\/p>\n<p>Thank You!!..<\/p>\n","protected":false},"excerpt":{"rendered":"<p>in this blog, we are going to how to get customer data by id using API repository and\u00a0 Factory Method There are two ways to get customer data that you can use. You can also get its product data through customer data. \u21d2 Using API Repository to Get Customer Data: protected $_customerRepositoryInterface; public function __construct( [&hellip;]<\/p>\n","protected":false},"author":670,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3290","post","type-post","status-publish","format-standard","hentry","category-magento-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to get customer data by id in Magneto 2 - cynoinfotech<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/\"},\"author\":{\"name\":\"Arjun Makadiya\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/person\\\/f1be8186602d3ebf417cf58baf125f24\"},\"headline\":\"How to get customer data by id in Magneto 2\",\"datePublished\":\"2022-07-13T12:37:45+00:00\",\"dateModified\":\"2022-07-13T12:44:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/\"},\"wordCount\":92,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\"},\"articleSection\":[\"Magento blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/\",\"name\":\"How to get customer data by id in Magneto 2 - cynoinfotech\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#website\"},\"datePublished\":\"2022-07-13T12:37:45+00:00\",\"dateModified\":\"2022-07-13T12:44:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-id-magneto-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get customer data by id in Magneto 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\",\"name\":\"cynoinfotech\",\"description\":\"web design &amp; development\",\"publisher\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\",\"name\":\"Cynoinfotech\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.cynoinfotech.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/final-logo-ci.png\",\"contentUrl\":\"https:\\\/\\\/www.cynoinfotech.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/final-logo-ci.png\",\"width\":240,\"height\":70,\"caption\":\"Cynoinfotech\"},\"image\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/cynoinfotech\\\/\",\"https:\\\/\\\/x.com\\\/cynoinfotech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/person\\\/f1be8186602d3ebf417cf58baf125f24\",\"name\":\"Arjun Makadiya\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"caption\":\"Arjun Makadiya\"},\"description\":\"Arjun Makadiya is a Junior Magento Developer at Cynoifotech. He is passionate about technology. Apart from work he likes to play cricket.\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/author\\\/arjun-makadiya\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get customer data by id in Magneto 2 - cynoinfotech","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/#article","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/"},"author":{"name":"Arjun Makadiya","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24"},"headline":"How to get customer data by id in Magneto 2","datePublished":"2022-07-13T12:37:45+00:00","dateModified":"2022-07-13T12:44:53+00:00","mainEntityOfPage":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/"},"wordCount":92,"commentCount":0,"publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"articleSection":["Magento blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/","url":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/","name":"How to get customer data by id in Magneto 2 - cynoinfotech","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/#website"},"datePublished":"2022-07-13T12:37:45+00:00","dateModified":"2022-07-13T12:44:53+00:00","breadcrumb":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-id-magneto-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cynoinfotech.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to get customer data by id in Magneto 2"}]},{"@type":"WebSite","@id":"https:\/\/cynoinfotech.com\/blog\/#website","url":"https:\/\/cynoinfotech.com\/blog\/","name":"cynoinfotech","description":"web design &amp; development","publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cynoinfotech.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cynoinfotech.com\/blog\/#organization","name":"Cynoinfotech","url":"https:\/\/cynoinfotech.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png","contentUrl":"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png","width":240,"height":70,"caption":"Cynoinfotech"},"image":{"@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cynoinfotech\/","https:\/\/x.com\/cynoinfotech"]},{"@type":"Person","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24","name":"Arjun Makadiya","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","caption":"Arjun Makadiya"},"description":"Arjun Makadiya is a Junior Magento Developer at Cynoifotech. He is passionate about technology. Apart from work he likes to play cricket.","url":"https:\/\/cynoinfotech.com\/blog\/author\/arjun-makadiya\/"}]}},"_links":{"self":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/users\/670"}],"replies":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=3290"}],"version-history":[{"count":4,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3290\/revisions"}],"predecessor-version":[{"id":3294,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3290\/revisions\/3294"}],"wp:attachment":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=3290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=3290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=3290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}