cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 Webervices Api

Magento2 Webervices Api

Following are the few queries related to Webservices API in Magento2.


1) Where is api.php in magento2 ?

2) How can we use Webservices in Magento2 ?

3) Can we convert and use webservices developed for Magento 1.X to Magento2. If yes Kindly share the procedure to do so.

5 REPLIES

Re: Magento2 Webervices Api

Hi @devjyot sharma, have you seen our dev docs for Magento 2 APIs? http://devdocs.magento.com/guides/v2.0/get-started/bk-get-started-api.html

--

Community Manager, Magento
Problem solved? Click Accept as Solution!
Still stuck? Check out our documentation: https://magento.com/resources/technical

Re: Magento2 Webervices Api

Hi Sherie,

 

I have already gone through the link that you have provided. 

But this URL doesn't answer my queries.

Kindly go through my queries once and do let me know the possible solutions

 

 

Thanks

 

Re: Magento2 Webervices Api

Hi Sherie,

I have few more questions related to Magento 2 Rest API's.
I want to use PUT, POST and DELETE methods in REST FUL API via URL something like this "http://localhost/magento2/rest/V1/products/MH01/ "
The GET method is working fine but I have no idea how to use the remaining methods.

I have one scenario to share with you. Kindly take a look at below details

<route url="/V1/products/:sku" method="PUT">
<service class="Magento\Catalog\Api\ProductRepositoryInterface" method="save" />
<resources>
<resource ref="Magento_Catalog:Smiley Tongueroducts" />
</resources>
</route>

<route url="/V1/products/:sku" method="DELETE">
<service class="Magento\Catalog\Api\ProductRepositoryInterface" method="deleteById"/>
<resources>
<resource ref="Magento_Catalog:Smiley Tongueroducts" />
</resources>
</route>

<route url="/V1/products/:sku" method="GET">
<service class="Magento\Catalog\Api\ProductRepositoryInterface" method="get"/>
<resources>
<resource ref="anonymous" />
</resources>
</route>

Here all the above routes are having same URL but different methods, If I fire the above mentioned URL in the browser the GET method route will work as the GET method is the default one but how to use PUT or POST by using the URL only.

Kindly reply me on this as this is very important. There are no such docs available explaining the use of PUT, POST and DELETE methods.

Thanks

Tags (1)

Re: Magento2 Webervices Api

Hi @devjyot sharma,

 

You do GET, POST, PUT, DELETE pretty much the same way with different data though. Here is an example for creating a product and retrieve it.

 

POST: /V1/products/

{"product" :
{
"sku": "simple1",
"name": "simple1",
"store_id": 1,
"attribute_set_id": 4,
"price": 5,
"status": 1,
"visibility": 4,
"type_id": "simple",
"weight": 2.5
}
}

 

GET: V1/products/simple1

 

And if you are in latest release, you can access all the REST endpoints through Swagger UI from your Magento instance:

<Magento Server>/swagger

 

Thanks,

 

Re: Magento2 Webervices Api

Hey Jitest,

 

Thanks for your reply.

 

I am trying to post the data using CURL, I tried passing the product json string that you have provided, but found the following error.

{"message":"Invalid type for value: \"array\". Expected Type: \"string\"."}

 

Rather than this I am also not able to pass array to post data using CURL. Is it that we can only post data using JSON via CURL?

 

Kindly provide solution to this issue as it is an important concern.

 

 

Regards,

Devjyot