forked from magento/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting_rest_resources.html
137 lines (111 loc) · 8.81 KB
/
testing_rest_resources.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
layout: m1x_rest
title: Testing REST Resources
---
<p>Three steps are required for utilizing REST API resources:</p>
<ul>
<li><a href="http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html" title="OAuth Authentication">Authenticate the user</a> (receive the access token for further steps);</li>
<li>Configure the <a href="http://www.magentocommerce.com/api/rest/permission_settings/roles_configuration.html" title="REST Roles Configuration">permissions for operations</a> and <a href="http://www.magentocommerce.com/api/rest/permission_settings/attributes_configuration.html" title="REST Attributes Configuration">attributes</a> for the type of the user;</li>
<li>Make an API call.</li>
</ul>
<p>The following headers are required for the call:</p>
<ul>
<li>Authorization</li>
<li>Version</li>
<li>Accept</li>
<li>Content-type</li>
</ul>
<p>The following parameters must be provided in the Authorization header for the call:</p>
<ul>
<li>oauth_signature_method</li>
<li>oauth_version</li>
<li>oauth_nonce</li>
<li>oauth_timestamp</li>
<li>oauth_consumer_key</li>
<li>oauth_token</li>
<li>oauth_signature</li>
</ul>
<h4><a name="TestingRESTResourceswithRESTClientsonDifferentBrowsers-TestingRESTresourceswiththeRESTClienthttps%3A%2F%2Faddons.mozilla.org%2FenUS%2Ffirefox%2Faddon%2Frestclient%2FpluginfortheMozillaFirefoxbrowser."></a>Testing REST resources with the <a href="https://addons.mozilla.org/en-US/firefox/addon/restclient/">REST Client</a> plugin for the Mozilla Firefox browser.</h4>
<ol>
<li>Open the REST Client.</li>
<li>From the Authentication drop-down, select <b>OAuth</b>.<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test1.png" style="border: 1px solid black"/></li>
<li>In the OAuth window, on the Signature for the request tab, fill in the following fields:<br/>
<ul>
<li><b>Consumer key</b>: Enter the <b>Key</b> value provided when you created the consumer in Magento Admin Panel.</li>
<li><b>Consumer secret</b>: Enter the <b>Secret</b> value provided when you created the consumer in Magento Admin Panel.</li>
<li><b>Access token</b>: Enter the oauth_token value received when you authenticated the application.</li>
<li><b>Access token secret</b>: Enter the oauth_token_secret value received when you authenticated the application.</li>
</ul>
</li>
<li>On the OAuth setting tab, define the following options:
<img src="{{ site.baseurl }}common/images/m1x/rest_test_oauth_tab.png" width="600" style="border: 1px solid black"/>
<ul>
<li><b>Signature Methods</b>: From the drop-down list, select which method will be used for signatures (HMAC-SHA1 or PLAINTEXT).</li>
<li><b>oAuth Version</b>: From the drop-down list, select the <b>1.0</b> option (REST API supports OAuth 1.0a).</li>
<li>Leave the <b>Realm</b>, <b>oAuth Nonce</b>, and <b>oAuth Timestemp</b> values set by default.</li>
</ul>
</li>
<li>Click <b>Save</b> and wait for the confirmation dialog to close.<br/>
<li>Return to the Signature for the request tab and select <b>Insert > Insert as header</b>.
<img src="{{ site.baseurl }}common/images/m1x/rest_test_insert.png" width="600" style="border: 1px solid black"/>
<p>An authorization header is created on the main page of REST Client. </p>
<img src="{{ site.baseurl }}common/images/m1x/rest_test_authheader.png" width="600" style="border: 1px solid black"/>
</li>
<b>NOTE</b>: Click the header with authorization data and click <b>Auto refresh</b> in the opened pop-up in order to generate new values for oauth_nonce, oauth_timestamp, and oauth_signature at each request.<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test3.png" style="border: 1px solid black"/></span></li>
<li>From the <b>Headers</b> drop-down, select <b>Custom Header</b>.<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test4.png" style="border: 1px solid black"/></span></li>
<li>In the <b>Request Header</b> window, enter "Content-Type" in the <b>Name</b> field and "text/xml" in the <b>Value</b> field (if you want to use the XML data format). To use the JSON request data format, enter application/json instead of the text/xml value.</li>
<li>Click <b>Okay</b>.<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test5.png" style="border: 1px solid black"/></span></li>
</ol>
<p><b>Example: Retrieving the List of Products</b></p>
<ol>
<li>From the <b>Method</b> drop-down list, select the <b>GET</b> option.</li>
<li>In the <b>URL</b> field, enter the following URL: <a href="http://magentohost/api/rest/products">http://magentohost/api/rest/products</a>. You can limit the number of products returned in the response. To set the limit to 4, enter the following URL: <a href="http://magentohost/api/rest/products?limit=4">http://magentohost/api/rest/products?limit=4</a></li>
<li>Click <b>Send</b>. Information about all products will be displayed in the response body. Example is as follows:<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test6.png" style="border: 1px solid black"/></span></li>
</ol>
<h4><a name="TestingRESTResourceswithRESTClientsonDifferentBrowsers-TestingRESTresourceswiththeAdvancedRESTClienthttps%3A%2F%2Fchrome.google.com%2Fwebstore%2Fdetail%2FhgmloofddffdnphfgcellkdfbfbjelooforGoogleChromebrowser."></a>Testing REST resources with the <a href="https://chrome.google.com/webstore/detail/hgmloofddffdnphfgcellkdfbfbjeloo">Advanced REST Client</a> for Google Chrome browser.</h4>
<ol>
<li>Open the Advanced REST Client Application.<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test7.png" style="border: 1px solid black"/></span></li>
<li>In the <b>Headers</b> box, select the <b>Form</b> tab.</li>
<li>In the first field, start typing <em>authorization</em>. An <b>Authorization</b> popup appears. Click it.<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test8.png" style="border: 1px solid black"/></span></li>
<li>When you click the fields next to the Authorization header, the <b>Construct</b> link appears. Click it to configure OAuth authentication.</li>
<li>The Authorization window opens. Select the OAuth tab.<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test9.png" style="border: 1px solid black"/></span></li>
<li>In the <b>Type</b> group of options, select the <b>Signed Request</b> option.</li>
<li>In the <b>signature method</b> group of options, select which method will be used for signatures (HMAC-SHA1 or PLAINTEXT).</li>
<li>Fill in the following data:<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test10.png" style="border: 1px solid black"/></span>
<ul>
<li><b>Consumer key</b>: Enter the <b>Key</b> value provided when you created the consumer in Magento Admin Panel.</li>
<li><b>Consumer secret</b>: Enter the <b>Secret</b> value provided when you created the consumer in Magento Admin Panel.</li>
<li><b>Access Token</b>: Enter the oauth_token value received when you authenticated the application.</li>
<li><b>Access Token Secret</b>: Enter the oauth_token_secret value received when you authenticated the application.</li>
</ul>
</li>
<li>Click <b>OK</b>.<br/>
<b>NOTE</b>: Advanced REST Client does not save the <b>Consumer secret</b> and <b>Access Token Secret</b> values. You need to enter these values each time you make a request.</li>
<li>In the <b>URL</b> field, enter the URL to which the API call will be performed and select the required HTTP method.</li>
<li>In the <b>Headers</b> table, click <b>Add row</b> and add the Accept - application/json or Accept - text/xml header depending on which format you prefer for the returned data.</li>
<li>Click <b>Send Request</b>.</li>
</ol>
<p><b>Example: Retrieving the list of customers</b></p>
<ol>
<li>In the <b>Method</b> group of options, select the <b>GET</b> option.</li>
<li>In the URL field, enter the following URL: <a href="http://magentohost/api/rest/customers">http://magentohost/api/rest/customers</a>.</li>
<li>Click <b>Send request</b>. Information about all customers will be displayed in the response body. Note that only Admin type of the user can retrieve the list of customers. Example is as follows:<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test11.png" style="border: 1px solid black"/></span></li>
</ol>
<p><b>Example: Creating a customer address</b></p>
<ol>
<li>In the <b>Method</b> group of options, select the <b>POST</b> option.</li>
<li>In the URL field, enter the following URL: <a href="http://magentohost/api/rest/customers/:id/addresses">http://magentohost/api/rest/customers/:id/addresses</a> where the ":id" value is the customer ID in the system.</li>
<li>In the <b>Body</b> table, on the <b>Raw input</b> tab, enter the data required for customer address creation.</li>
<li>Click <b>Send request</b>. If the address is created, the 200 OK HTTP status code will be returned. Example is as follows:<br/>
<img src="{{ site.baseurl }}common/images/m1x/rest_test12.png" style="border: 1px solid black"/></span></li>
</ol>