SlideShare a Scribd company logo
1 of 21
Download to read offline
1
APIinMagento2:
whatyoucanandyoucan'tdo
Andralungu @iamspringerin
2
WhoAmi
Andra Lungu - @iamspringerin
Magento Developer @Bitbull_IT
3+ magento development
3+ .net/java development
Andralungu @iamspringerin
3
WhY
ERP
SHOPPING
APP
CRM CMS
Javascript
widgets
WAREHOUSE
Andralungu @iamspringerin
4
APIinMagento1
Supported Protocols
● XML-RPC
● SOAP V1
● SOAP V2 since M1.3, WS-I compliant since M1.6
● REST since M1.7 with less business logic then others protocols *
Authentication:
● API user with assigned roles similar to ACL roles
● * 3-legged OAuth 1.0a
Documentation
● http://devdocs.magento.com/guides/m1x/api/soap/introduction.html
● http://devdocs.magento.com/guides/m1x/api/rest-api-index.html
Andralungu @iamspringerin
5
APIinMagento2
Supported Protocols
● SOAP
● REST
Authentication:
● OAuth 1.0a 2-legged suggested for third-party applications
● Tokens suggested for mobile applications
● Session based
Documentation
● http://devdocs.magento.com/guides/v2.1/rest/bk-rest.html
● http://devdocs.magento.com/guides/v2.1/soap/bk-soap.html
Andralungu @iamspringerin
6
AUTHmagento2
User type
● Administrator or Integration
● Customer
● Guest user
Authorized resources. Example if authorized for the
Magento_Customer::group resource, they can make a GET
/V1/customerGroups/:id call.
Resources with anonymous or self permission.
Resources with anonymous permission.
Andralungu @iamspringerin
7
AUTHmagento2acl.xml permissions to access the resources
…...
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="Magento_Customer::config_customer" title="Customers Section" translate="title" sortOrder="50" />
</resource>
</resource>
<resource id="Magento_Backend::stores_other_settings">
<resource id="Magento_Customer::group" title="Customer Groups" translate="title" sortOrder="10" />
</resource>
</resource>
……….
Andralungu @iamspringerin
8
AUTHmagento2
webapi.xml reference the permission needed for each api resource
<route url="/V1/customers/:email/activate" method="PUT">
<service class="MagentoCustomerApiAccountManagementInterface" method="activate"/>
<resources>
<resource ref="Magento_Customer::manage"/>
</resources>
</route>
<route url="/V1/customers/me/password" method="PUT">
<service class="MagentoCustomerApiAccountManagementInterface" method="changePasswordById"/>
<resources>
<resource ref="self"/>
</resources>
<data>
<parameter name="customerId" force="true">%customer_id%</parameter>
</data>
</route>
<route url="/V1/customers/:customerId/password/resetLinkToken/:resetPasswordLinkToken" method="GET">
<service class="MagentoCustomerApiAccountManagementInterface" method="validateResetPasswordLinkToken"/>
<resources>
<resource ref="anonymous"/>
</resources>
Andralungu @iamspringerin
9
OAUTH1.0abasedauth
● Requires implementation of the protocol on client side
● Add integration in the admin area and activate it
Andralungu @iamspringerin
10
Tokenbasedauthcurl -X POST
"https://magento.host/index.php/rest/V1/integration/customer/token"  -H
"Content-Type:application/json"  -d '{"username":"customer1@example.com",
"password":"customer1pw"}'
authorization: Bearer nj9plnx828w23ppp5u8e0po9sjrkqe0d
Andralungu @iamspringerin
11
SeSsionbasedauth
Self access enables a user to access resources they own.
For example, GET /V1/customers/me fetches the logged-in customer's
details typically useful for JavaScript-based widgets.
Andralungu @iamspringerin
12
BACKWARDSCOMPATIBILITY
&PHPannotations
Semantic Versioning MAJOR.MINOR.PATCH
● MAJOR indicates incompatible API changes
● MINOR indicates backward-compatible functionality has been added
● PATCH indicates backward-compatible bug fixes
Andralungu @iamspringerin
13
BACKWARDSCOMPATIBILITY
&PHPannotationsBackward compatible applies for classes and methods annotated
with @api within MINOR and PATCH updates to our components.
As changes are introduced, methods are annotated with
@deprecated and removed only with the next MAJOR component
version.
BACKWARDSCOMPATIBILITY
&PHPannotations
Andralungu @iamspringerin
14
BACKWARDSCOMPATIBILITY
&PHPannotationsMagento uses reflection to automatically create classes and sets data submitted in JSON or HTTP
array syntax onto an instance of the expected PHP class when calling the service method.
Conversely, if an object is returned from one of these methods, Magento automatically converts
that PHP object into a JSON or SOAP object before sending it over the web API.
BACKWARDSCOMPATIBILITY
&PHPannotations
Andralungu @iamspringerin
15
BACKWARDSCOMPATIBILITY
&PHPannotationsAll methods exposed by the web API must follow these rules
● Parameters must be defined in the doc block as * @param type $paramName
● Return type must be defined in the doc block as * @return type
● Valid object types include a fully qualified class name or a fully qualified interface name.
● Any parameters or return values of type array can be denoted by following any of the previous types by
an empty set of square brackets []
BACKWARDSCOMPATIBILITY
&PHPannotations
Andralungu @iamspringerin
16
cuSTOMIZEANAPI:
Extension Attributes
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="MagentoCatalogApiDataProductInterface">
<attribute code="stock_item" type="MagentoCatalogInventoryApiDataStockItemInterface">
<resources>
<resource ref="Magento_CatalogInventory::cataloginventory"/>
</resources>
</attribute>
</extension_attributes>
</config>
Andralungu @iamspringerin
17
CREATEANAPI
18
CREATEANAPI
Never been easier !!!
Bitbull/CustomApi/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="BitbullCustomApiApiMagentoSeminarInterface"
type="BitbullCustomApiModelMagentoSeminar" />
</config>
Bitbull/CustomApi/etc/webapi.xml
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/magentoseminar/:eventName" method="GET">
<service class="BitbullCustomApiApiMagentoSeminarInterface" method="getAwesomeEvent"/>
<resources>
<resource ref="Magento_Catalog::products" />
</resources>
</route>
</routes>
Andralungu @iamspringerin
19
CREATEANAPI
Bitbull/CustomApi/Api/MagentoSeminarInterface.php
namespace BitbullCustomApiApi;
/**
* @api
*/
interface MagentoSeminarInterface
{
/**
* Get info about the conference
* @api
* @param string $eventName
* @return string
*/
public function getAwesomeEvent($eventName);
}
Andralungu @iamspringerin
20
CREATEANAPI
Bitbull/CustomApi/Model/MagentoSeminar.php
namespace BitbullCustomApiModel;
class MagentoSeminar implements BitbullCustomApiApiMagentoSeminarInterface
{
/*
* @api
* @param string $conferenceName
* @return string
*/
public function getAwesomeEvent($eventName)
{
return $eventName . ' is an awesome event';
}
}
Andralungu @iamspringerin
21
QUestions
Thank you
Andralungu @iamspringerin

More Related Content

Similar to Api in magento 2

7 network programmability concepts python-ansible
7 network programmability concepts python-ansible7 network programmability concepts python-ansible
7 network programmability concepts python-ansibleSagarR24
 
The Complete Guide to API Development in 2022.pdf
The Complete Guide to API Development in 2022.pdfThe Complete Guide to API Development in 2022.pdf
The Complete Guide to API Development in 2022.pdfConcetto Labs
 
APIdays Paris 2014 - Workshop - Craft and Deploy Your API in a Few Clicks Wit...
APIdays Paris 2014 - Workshop - Craft and Deploy Your API in a Few Clicks Wit...APIdays Paris 2014 - Workshop - Craft and Deploy Your API in a Few Clicks Wit...
APIdays Paris 2014 - Workshop - Craft and Deploy Your API in a Few Clicks Wit...Restlet
 
Highlights of WSO2 API Manager 4.0.0
Highlights of WSO2 API Manager 4.0.0Highlights of WSO2 API Manager 4.0.0
Highlights of WSO2 API Manager 4.0.0WSO2
 
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...Jitendra Bafna
 
Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Igor Miniailo
 
API Design Best Practices by Igor Miniailo
API Design Best Practices by Igor MiniailoAPI Design Best Practices by Igor Miniailo
API Design Best Practices by Igor MiniailoMagecom UK Limited
 
INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...
INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...
INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...apidays
 
Extend soa with api management Sangam18
Extend soa with api management Sangam18Extend soa with api management Sangam18
Extend soa with api management Sangam18Vinay Kumar
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIsAparna Sharma
 
A Practical Guide to Automating End-to-End API Testing
A Practical Guide to Automating End-to-End API TestingA Practical Guide to Automating End-to-End API Testing
A Practical Guide to Automating End-to-End API TestingpCloudy
 
[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políti...
[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políti...[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políti...
[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políti...jorgelebrato
 
RefCard API Architecture Strategy
RefCard API Architecture StrategyRefCard API Architecture Strategy
RefCard API Architecture StrategyOCTO Technology
 
API (Application program interface)
API (Application program interface)API (Application program interface)
API (Application program interface)Muhammad Jahanzaib
 
How to build Simple yet powerful API.pptx
How to build Simple yet powerful API.pptxHow to build Simple yet powerful API.pptx
How to build Simple yet powerful API.pptxChanna Ly
 
Nordic API days 2016 - APIs.guru Wikipedia for Web APIs
Nordic API days 2016 - APIs.guru Wikipedia for Web APIsNordic API days 2016 - APIs.guru Wikipedia for Web APIs
Nordic API days 2016 - APIs.guru Wikipedia for Web APIsIvan Goncharov
 

Similar to Api in magento 2 (20)

Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
7 network programmability concepts python-ansible
7 network programmability concepts python-ansible7 network programmability concepts python-ansible
7 network programmability concepts python-ansible
 
The Complete Guide to API Development in 2022.pdf
The Complete Guide to API Development in 2022.pdfThe Complete Guide to API Development in 2022.pdf
The Complete Guide to API Development in 2022.pdf
 
APIdays Paris 2014 - Workshop - Craft and Deploy Your API in a Few Clicks Wit...
APIdays Paris 2014 - Workshop - Craft and Deploy Your API in a Few Clicks Wit...APIdays Paris 2014 - Workshop - Craft and Deploy Your API in a Few Clicks Wit...
APIdays Paris 2014 - Workshop - Craft and Deploy Your API in a Few Clicks Wit...
 
Highlights of WSO2 API Manager 4.0.0
Highlights of WSO2 API Manager 4.0.0Highlights of WSO2 API Manager 4.0.0
Highlights of WSO2 API Manager 4.0.0
 
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
 
Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2
 
REST API Basics
REST API BasicsREST API Basics
REST API Basics
 
API Design Best Practices by Igor Miniailo
API Design Best Practices by Igor MiniailoAPI Design Best Practices by Igor Miniailo
API Design Best Practices by Igor Miniailo
 
INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...
INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...
INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...
 
Extend soa with api management Sangam18
Extend soa with api management Sangam18Extend soa with api management Sangam18
Extend soa with api management Sangam18
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIs
 
A Practical Guide to Automating End-to-End API Testing
A Practical Guide to Automating End-to-End API TestingA Practical Guide to Automating End-to-End API Testing
A Practical Guide to Automating End-to-End API Testing
 
Api Testing.pdf
Api Testing.pdfApi Testing.pdf
Api Testing.pdf
 
[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políti...
[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políti...[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políti...
[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políti...
 
RefCard API Architecture Strategy
RefCard API Architecture StrategyRefCard API Architecture Strategy
RefCard API Architecture Strategy
 
API (Application program interface)
API (Application program interface)API (Application program interface)
API (Application program interface)
 
How to build Simple yet powerful API.pptx
How to build Simple yet powerful API.pptxHow to build Simple yet powerful API.pptx
How to build Simple yet powerful API.pptx
 
SVQdotNET: Building APIs with OpenApi
SVQdotNET: Building APIs with OpenApiSVQdotNET: Building APIs with OpenApi
SVQdotNET: Building APIs with OpenApi
 
Nordic API days 2016 - APIs.guru Wikipedia for Web APIs
Nordic API days 2016 - APIs.guru Wikipedia for Web APIsNordic API days 2016 - APIs.guru Wikipedia for Web APIs
Nordic API days 2016 - APIs.guru Wikipedia for Web APIs
 

Recently uploaded

Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Roomishabajaj13
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$kojalkojal131
 

Recently uploaded (20)

Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 

Api in magento 2

  • 2. 2 WhoAmi Andra Lungu - @iamspringerin Magento Developer @Bitbull_IT 3+ magento development 3+ .net/java development Andralungu @iamspringerin
  • 4. 4 APIinMagento1 Supported Protocols ● XML-RPC ● SOAP V1 ● SOAP V2 since M1.3, WS-I compliant since M1.6 ● REST since M1.7 with less business logic then others protocols * Authentication: ● API user with assigned roles similar to ACL roles ● * 3-legged OAuth 1.0a Documentation ● http://devdocs.magento.com/guides/m1x/api/soap/introduction.html ● http://devdocs.magento.com/guides/m1x/api/rest-api-index.html Andralungu @iamspringerin
  • 5. 5 APIinMagento2 Supported Protocols ● SOAP ● REST Authentication: ● OAuth 1.0a 2-legged suggested for third-party applications ● Tokens suggested for mobile applications ● Session based Documentation ● http://devdocs.magento.com/guides/v2.1/rest/bk-rest.html ● http://devdocs.magento.com/guides/v2.1/soap/bk-soap.html Andralungu @iamspringerin
  • 6. 6 AUTHmagento2 User type ● Administrator or Integration ● Customer ● Guest user Authorized resources. Example if authorized for the Magento_Customer::group resource, they can make a GET /V1/customerGroups/:id call. Resources with anonymous or self permission. Resources with anonymous permission. Andralungu @iamspringerin
  • 7. 7 AUTHmagento2acl.xml permissions to access the resources …... <acl> <resources> <resource id="Magento_Backend::admin"> <resource id="Magento_Backend::stores"> <resource id="Magento_Backend::stores_settings"> <resource id="Magento_Config::config"> <resource id="Magento_Customer::config_customer" title="Customers Section" translate="title" sortOrder="50" /> </resource> </resource> <resource id="Magento_Backend::stores_other_settings"> <resource id="Magento_Customer::group" title="Customer Groups" translate="title" sortOrder="10" /> </resource> </resource> ………. Andralungu @iamspringerin
  • 8. 8 AUTHmagento2 webapi.xml reference the permission needed for each api resource <route url="/V1/customers/:email/activate" method="PUT"> <service class="MagentoCustomerApiAccountManagementInterface" method="activate"/> <resources> <resource ref="Magento_Customer::manage"/> </resources> </route> <route url="/V1/customers/me/password" method="PUT"> <service class="MagentoCustomerApiAccountManagementInterface" method="changePasswordById"/> <resources> <resource ref="self"/> </resources> <data> <parameter name="customerId" force="true">%customer_id%</parameter> </data> </route> <route url="/V1/customers/:customerId/password/resetLinkToken/:resetPasswordLinkToken" method="GET"> <service class="MagentoCustomerApiAccountManagementInterface" method="validateResetPasswordLinkToken"/> <resources> <resource ref="anonymous"/> </resources> Andralungu @iamspringerin
  • 9. 9 OAUTH1.0abasedauth ● Requires implementation of the protocol on client side ● Add integration in the admin area and activate it Andralungu @iamspringerin
  • 10. 10 Tokenbasedauthcurl -X POST "https://magento.host/index.php/rest/V1/integration/customer/token" -H "Content-Type:application/json" -d '{"username":"customer1@example.com", "password":"customer1pw"}' authorization: Bearer nj9plnx828w23ppp5u8e0po9sjrkqe0d Andralungu @iamspringerin
  • 11. 11 SeSsionbasedauth Self access enables a user to access resources they own. For example, GET /V1/customers/me fetches the logged-in customer's details typically useful for JavaScript-based widgets. Andralungu @iamspringerin
  • 12. 12 BACKWARDSCOMPATIBILITY &PHPannotations Semantic Versioning MAJOR.MINOR.PATCH ● MAJOR indicates incompatible API changes ● MINOR indicates backward-compatible functionality has been added ● PATCH indicates backward-compatible bug fixes Andralungu @iamspringerin
  • 13. 13 BACKWARDSCOMPATIBILITY &PHPannotationsBackward compatible applies for classes and methods annotated with @api within MINOR and PATCH updates to our components. As changes are introduced, methods are annotated with @deprecated and removed only with the next MAJOR component version. BACKWARDSCOMPATIBILITY &PHPannotations Andralungu @iamspringerin
  • 14. 14 BACKWARDSCOMPATIBILITY &PHPannotationsMagento uses reflection to automatically create classes and sets data submitted in JSON or HTTP array syntax onto an instance of the expected PHP class when calling the service method. Conversely, if an object is returned from one of these methods, Magento automatically converts that PHP object into a JSON or SOAP object before sending it over the web API. BACKWARDSCOMPATIBILITY &PHPannotations Andralungu @iamspringerin
  • 15. 15 BACKWARDSCOMPATIBILITY &PHPannotationsAll methods exposed by the web API must follow these rules ● Parameters must be defined in the doc block as * @param type $paramName ● Return type must be defined in the doc block as * @return type ● Valid object types include a fully qualified class name or a fully qualified interface name. ● Any parameters or return values of type array can be denoted by following any of the previous types by an empty set of square brackets [] BACKWARDSCOMPATIBILITY &PHPannotations Andralungu @iamspringerin
  • 16. 16 cuSTOMIZEANAPI: Extension Attributes <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> <extension_attributes for="MagentoCatalogApiDataProductInterface"> <attribute code="stock_item" type="MagentoCatalogInventoryApiDataStockItemInterface"> <resources> <resource ref="Magento_CatalogInventory::cataloginventory"/> </resources> </attribute> </extension_attributes> </config> Andralungu @iamspringerin
  • 18. 18 CREATEANAPI Never been easier !!! Bitbull/CustomApi/etc/di.xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="BitbullCustomApiApiMagentoSeminarInterface" type="BitbullCustomApiModelMagentoSeminar" /> </config> Bitbull/CustomApi/etc/webapi.xml <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd"> <route url="/V1/magentoseminar/:eventName" method="GET"> <service class="BitbullCustomApiApiMagentoSeminarInterface" method="getAwesomeEvent"/> <resources> <resource ref="Magento_Catalog::products" /> </resources> </route> </routes> Andralungu @iamspringerin
  • 19. 19 CREATEANAPI Bitbull/CustomApi/Api/MagentoSeminarInterface.php namespace BitbullCustomApiApi; /** * @api */ interface MagentoSeminarInterface { /** * Get info about the conference * @api * @param string $eventName * @return string */ public function getAwesomeEvent($eventName); } Andralungu @iamspringerin
  • 20. 20 CREATEANAPI Bitbull/CustomApi/Model/MagentoSeminar.php namespace BitbullCustomApiModel; class MagentoSeminar implements BitbullCustomApiApiMagentoSeminarInterface { /* * @api * @param string $conferenceName * @return string */ public function getAwesomeEvent($eventName) { return $eventName . ' is an awesome event'; } } Andralungu @iamspringerin