{"id":7915,"date":"2021-05-02T13:53:10","date_gmt":"2021-05-02T13:53:10","guid":{"rendered":"https:\/\/www.bay20.com\/?p=7915"},"modified":"2025-05-21T16:23:33","modified_gmt":"2025-05-21T10:38:33","slug":"benutzerdefinierte-api-fur-magento-2","status":"publish","type":"post","link":"https:\/\/www.bay20.com\/de\/benutzerdefinierte-api-fur-magento-2\/","title":{"rendered":"Benutzerdefinierte API f\u00fcr Magento 2"},"content":{"rendered":"\n<p>Benutzerdefinierte API in <a href=\"https:\/\/www.bay20.com\/de\/mieten-magento2-entwickler\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"https:\/\/www.bay20.com\/hire-magento2-developer\/\">magento 2<\/a> bedeutet, dass Online-H\u00e4ndler eine Anwendungsprogrammierschnittstelle f\u00fcr den eigenen Gebrauch nutzen k\u00f6nnen. API ist ein notwendiges Element, um eine Verbindung zwischen den Daten herzustellen, wenn Sie ein Programm oder eine Dienstleistung von anderen Websites anfordern. Mit API&#8217;s k\u00f6nnen Sie leicht alle Bausteine erhalten, um ein Programm erfolgreich zu initiieren.<\/p>\n\n\n\n<p>Sie k\u00f6nnen api auf<em> http:\/\/&lt;yourhost&gt;\/swagger<\/em><\/p>\n\n\n\n<p>Die Anwendungsprogrammierschnittstelle erm\u00f6glicht den Zugriff auf Daten aus einer Anwendung. API kann als Mittelsmann zwischen einem Programmierer und einer Anwendung bezeichnet werden.<\/p>\n\n\n\n<p>Los geht&#8217;s<\/p>\n\n\n\n<p><strong>Erstellen und aktivieren Sie ein Modul.<\/strong><\/p>\n\n\n\n<p>Erstellen Sie eine registration.php in app\/code\/Bay20\/CustomApi\/ directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    'Bay20_CustomApi',\n    __DIR__\n);<\/code><\/pre>\n\n\n\n<p>Erstellen Sie module.xml in app\/code\/Bay20\/CustomApi\/etc\/ directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\"&gt;\n    &lt;module name=\"Bay20_CustomApi\" setup_version=\"1.0.0\"\/&gt;\n&lt;\/config&gt;<\/code><\/pre>\n\n\n\n<p>Nachdem Sie diese beiden Dateien erstellt haben, f\u00fchren Sie den Befehl<\/p>\n\n\n\n<p><em>php bin\/magento module:enable Bay20_CustomApi <\/em><\/p>\n\n\n\n<p><strong>Web-API-Konfiguration<\/strong><\/p>\n\n\n\n<p><em>app\/code\/Bay20\/CustomApi\/etc\/webapi.xml<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" ?&gt;\n&lt;routes xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Webapi:etc\/webapi.xsd\"&gt;\n\t&lt;route method=\"GET\" url=\"\/V1\/mageplaza-helloworld\/post\"&gt;\n\t\t&lt;service class=\"Bay20\\CustomApi\\Api\\PostManagementInterface\" method=\"getPost\"\/&gt;\n\t\t&lt;resources&gt;\n\t\t\t&lt;resource ref=\"anonymous\"\/&gt;\n\t\t&lt;\/resources&gt;\n\t&lt;\/route&gt;\n&lt;\/routes&gt;<\/code><\/pre>\n\n\n\n<p>Das Ressourcentag legt fest, welche Ressourcen der Benutzer ben\u00f6tigt, um auf diesen Api-Aufruf zugreifen zu k\u00f6nnen.<\/p>\n\n\n\n<p><strong>Schnittstelle definieren<\/strong><\/p>\n\n\n\n<p>In di.xml legen wir fest, welches Modell die Schnittstelle aufruft.<\/p>\n\n\n\n<p>app\/code\/Bay20\/CustomApi\/etc\/di.xml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" ?&gt;\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\"&gt;\n\t&lt;preference for=\"Bay20\\CustomApi\\Api\\PostManagementInterface\" \n    type=\"Bay20\\CustomApi\\Model\\PostManagement\"\/&gt;\n&lt;\/config&gt;<\/code><\/pre>\n\n\n\n<p><strong> Interface<\/strong><\/p>\n\n\n\n<p>app\/code\/Bay20\/CustomApi\/Api\/PostManagementInterface.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php \nnamespace Bay20\\CustomApi\\Api;\n\ninterface PostManagementInterface {\n\n\t\/**\n\t * GET for Post api\n\t * @param string $param\n\t * @return string\n\t *\/\n\n\tpublic function getPost($param);\n}<\/code><\/pre>\n\n\n\n<p><strong>Model<\/strong><\/p>\n\n\n\n<p>app\/code\/Bay20\/CustomApi\/Model\/PostManagement.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php \nnamespace Bay20\\CustomApi\\Model;\nclass PostManagement \n{\n\tpublic function getPost($param)\n\t{\n\t\treturn 'api GET return the $param ' . $param;\n\t}\n}<\/code><\/pre>\n\n\n\n<p>Innerhalb des Modells f\u00fcgen wir unsere Funktionalit\u00e4t hinzu, die durch den Aufruf einer API-Methode ausgef\u00fchrt wird.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Schlussfolgerung:<\/strong><\/p>\n\n\n\n<p>Mit Hilfe der oben genannten Dateien k\u00f6nnen Sie eine benutzerdefinierte Api in Magento 2 erstellen<\/p>\n\n\n\n<p><strong>Bitte kontaktieren Sie uns unter <strong><a href=\"mailto:manish@bay20.com\">manish@bay20.com<\/a><\/strong> oder rufen Sie uns unter <strong><a href=\"https:\/\/api.whatsapp.com\/send?phone=+918800519180&amp;text=Hi,%20I%20contacted%20you%20through%20your%20website.\" target=\"_blank\" rel=\"noreferrer noopener\">+91-8800519180<\/a><\/strong> an, wenn Sie Unterst\u00fctzung f\u00fcr Magento 2 ben\u00f6tigen. Sie k\u00f6nnen auch die <strong><a href=\"https:\/\/www.bay20.com\/de\/magento-entwicklungsunternehmen\/\">Magento2<strong>-Entwicklungsseite<\/strong><\/a><\/strong> besuchen, um die von uns angebotenen Dienstleistungen zu \u00fcberpr\u00fcfen.<\/strong><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Custom api in magento 2 means helping online retailers an Application Programming Interface for the own using. API is a required element to connect among the data if you ask for any program or service from other websites.<\/p>\n","protected":false},"author":1,"featured_media":8431,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77,79],"tags":[],"class_list":["post-7915","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","category-magento-anleitung"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/comments?post=7915"}],"version-history":[{"count":7,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7915\/revisions"}],"predecessor-version":[{"id":17289,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7915\/revisions\/17289"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media\/8431"}],"wp:attachment":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media?parent=7915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/categories?post=7915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/tags?post=7915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}