Skip to content

Commit e9af38a

Browse files
committed
Merge pull request #145 from aleachjr/update-readme
update readme to include oauth connection information
2 parents e549b03 + 172b768 commit e9af38a

File tree

1 file changed

+70
-54
lines changed

1 file changed

+70
-54
lines changed

README.md

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Requirements
1919
- PHP 5.3 or greater
2020
- cUrl extension enabled
2121

22-
To connect to the API, you need the following credentials:
22+
**To connect to the API with basic auth you need the following:**
2323

2424
- Secure URL pointing to a Bigcommerce store
2525
- Username of an authorized admin user of the store
@@ -28,34 +28,40 @@ To connect to the API, you need the following credentials:
2828
To generate an API key, go to Control Panel > Users > Edit User and make sure
2929
the 'Enable the XML API?' is ticked.
3030

31+
**To connect to the API with OAuth you will need the following:**
32+
33+
- client_id
34+
- auth_token
35+
- store_hash
36+
3137
Installation
3238
------------
3339

3440
Use the following Composer command to install the
3541
API client from [the Bigcommerce vendor on Packagist](https://packagist.org/packages/bigcommerce/api):
3642

37-
```
43+
~~~shell
3844
$ composer require bigcommerce/api
3945
$ composer update
40-
```
46+
~~~
4147

4248
You can also install composer for your specific project by running the following in the library folder.
4349

44-
```
45-
curl -sS https://getcomposer.org/installer | php
46-
php composer.phar install
47-
composer install
48-
```
50+
~~~shell
51+
$ curl -sS https://getcomposer.org/installer | php
52+
$ php composer.phar install
53+
$ composer install
54+
~~~
4955

5056
Namespace
5157
---------
5258

5359
All the examples below assume the `Bigcommerce\Api\Client` class is imported
5460
into the scope with the following namespace declaration:
5561

56-
```
62+
~~~php
5763
use Bigcommerce\Api\Client as Bigcommerce;
58-
```
64+
~~~
5965

6066
Configuration
6167
-------------
@@ -66,13 +72,23 @@ in your autoload path (using Composer’s `vendor/autoload.php` hook is recommen
6672
Provide your credentials to the static configuration hook to prepare the API client
6773
for connecting to a store on the Bigcommerce platform:
6874

69-
```
75+
### Basic Auth
76+
~~~php
7077
Bigcommerce::configure(array(
7178
'store_url' => 'https://store.mybigcommerce.com',
7279
'username' => 'admin',
73-
'api_key' => 'd81aada4c19c34d913e18f07fd7f36ca'
80+
'api_key' => 'd81aada4xc34xx3e18f0xxxx7f36ca'
81+
));
82+
~~~
83+
84+
### OAuth
85+
~~~php
86+
Bigcommerce::configure(array(
87+
'client_id' => 'xxxxxxxx',
88+
'auth_token' => 'xxxxxxx',
89+
'store_hash' => 'xxxxxxx'
7490
));
75-
```
91+
~~~
7692

7793
Connecting to the store
7894
-----------------------
@@ -82,68 +98,68 @@ the store, ping the getTime method which will return a DateTime object
8298
representing the current timestamp of the store if successful or false if
8399
unsuccessful:
84100

85-
```
101+
~~~php
86102
$ping = Bigcommerce::getTime();
87103

88104
if ($ping) echo $ping->format('H:i:s');
89-
```
105+
~~~
90106

91107
Accessing collections and resources (GET)
92108
-----------------------------------------
93109

94110
To list all the resources in a collection:
95111

96-
```
112+
~~~php
97113
$products = Bigcommerce::getProducts();
98114

99-
foreach($products as $product) {
115+
foreach ($products as $product) {
100116
echo $product->name;
101117
echo $product->price;
102118
}
103-
```
119+
~~~
104120

105121
To access a single resource and its connected sub-resources:
106122

107-
```
123+
~~~php
108124
$product = Bigcommerce::getProduct(11);
109125

110126
echo $product->name;
111127
echo $product->price;
112-
```
128+
~~~
113129

114130
To view the total count of resources in a collection:
115131

116-
```
132+
~~~php
117133
$count = Bigcommerce::getProductsCount();
118134

119135
echo $count;
120-
```
136+
~~~
121137
Paging and Filtering
122138
--------------------
123139

124140
All the default collection methods support paging, by passing
125141
the page number to the method as an integer:
126142

127-
```
143+
~~~php
128144
$products = Bigcommerce::getProducts(3);
129-
```
145+
~~~
130146
If you require more specific numbering and paging, you can explicitly specify
131147
a limit parameter:
132148

133-
```
149+
~~~php
134150
$filter = array("page" => 3, "limit" => 30);
135151

136152
$products = Bigcommerce::getProducts($filter);
137-
```
153+
~~~
138154

139155
To filter a collection, you can also pass parameters to filter by as key-value
140156
pairs:
141157

142-
```
158+
~~~php
143159
$filter = array("is_featured" => true);
144160

145161
$featured = Bigcommerce::getProducts($filter);
146-
```
162+
~~~
147163
See the API documentation for each resource for a list of supported filter
148164
parameters.
149165

@@ -152,25 +168,25 @@ Updating existing resources (PUT)
152168

153169
To update a single resource:
154170

155-
```
171+
~~~php
156172
$product = Bigcommerce::getProduct(11);
157173

158174
$product->name = "MacBook Air";
159175
$product->price = 99.95;
160176
$product->update();
161-
```
177+
~~~
162178

163179
You can also update a resource by passing an array or stdClass object of fields
164180
you want to change to the global update method:
165181

166-
```
182+
~~~php
167183
$fields = array(
168184
"name" => "MacBook Air",
169185
"price" => 999.95
170186
);
171187

172188
Bigcommerce::updateProduct(11, $fields);
173-
```
189+
~~~
174190

175191
Creating new resources (POST)
176192
-----------------------------
@@ -179,46 +195,46 @@ Some resources support creation of new items by posting to the collection. This
179195
can be done by passing an array or stdClass object representing the new
180196
resource to the global create method:
181197

182-
```
198+
~~~php
183199
$fields = array(
184200
"name" => "Apple"
185201
);
186202

187203
Bigcommerce::createBrand($fields);
188-
```
204+
~~~
189205

190206
You can also create a resource by making a new instance of the resource class
191207
and calling the create method once you have set the fields you want to save:
192208

193-
```
209+
~~~php
194210
$brand = new Bigcommerce\Api\Resources\Brand();
195211

196212
$brand->name = "Apple";
197213
$brand->create();
198-
```
214+
~~~
199215

200216
Deleting resources and collections (DELETE)
201217
-------------------------------------------
202218

203219
To delete a single resource you can call the delete method on the resource object:
204220

205-
```
221+
~~~php
206222
$category = Bigcommerce::getCategory(22);
207223
$category->delete();
208-
```
224+
~~~
209225

210226
You can also delete resources by calling the global wrapper method:
211227

212-
```
228+
~~~php
213229
Bigcommerce::deleteCategory(22);
214-
```
230+
~~~
215231

216232
Some resources support deletion of the entire collection. You can use the
217233
deleteAll methods to do this:
218234

219-
```
235+
~~~php
220236
Bigcommerce::deleteAllOptionSets();
221-
```
237+
~~~
222238

223239
Using The XML API
224240
-----------------
@@ -227,9 +243,9 @@ By default, the API client handles requests and responses by converting between
227243
JSON strings and their PHP object representations. If you need to work with XML
228244
you can switch the API into XML mode with the useXml method:
229245

230-
```
246+
~~~php
231247
Bigcommerce::useXml();
232-
```
248+
~~~
233249

234250
This will configure the API client to use XML for all subsequent requests. Note
235251
that the client does not convert XML to PHP objects. In XML mode, all object
@@ -238,7 +254,7 @@ containing valid XML, and all responses from collection and resource methods
238254
(including the ping, and count methods) will return XML strings instead of PHP
239255
objects. An example transaction using XML would look like:
240256

241-
```
257+
~~~php
242258
Bigcommerce::useXml();
243259

244260
$xml = "<?xml version="1.0" encoding="UTF-8"?>
@@ -248,7 +264,7 @@ $xml = "<?xml version="1.0" encoding="UTF-8"?>
248264
</brand>";
249265

250266
$result = Bigcommerce::createBrand($xml);
251-
```
267+
~~~
252268

253269
Handling Errors And Timeouts
254270
----------------------------
@@ -263,15 +279,15 @@ In some cases, you may also need to check the reason why the request failed.
263279
This would most often be when you tried to save some data that did not validate
264280
correctly.
265281

266-
```
282+
~~~php
267283
$orders = Bigcommerce::getOrders();
268284

269285
if (!$orders) {
270286
$error = Bigcommerce::getLastError();
271287
echo $error->code;
272288
echo $error->message;
273289
}
274-
```
290+
~~~
275291

276292
Returning false on errors, and using error objects to provide context is good
277293
for writing quick scripts but is not the most robust solution for larger and
@@ -282,7 +298,7 @@ throw exceptions when errors occur. Bear in mind, that if you do this, you will
282298
need to catch and handle the exception in code yourself. The exception throwing
283299
behavior of the client is controlled using the failOnError method:
284300

285-
```
301+
~~~php
286302
Bigcommerce::failOnError();
287303

288304
try {
@@ -292,7 +308,7 @@ try {
292308
echo $error->getCode();
293309
echo $error->getMessage();
294310
}
295-
```
311+
~~~
296312

297313
The exceptions thrown are subclasses of Error, representing
298314
client errors and server errors. The API documentation for response codes
@@ -307,9 +323,9 @@ Bigcommerce store. In cases where this is undesirable, or where an unsigned
307323
certificate is being used, you can turn off this behavior using the verifyPeer
308324
switch, which will disable certificate checking on all subsequent requests:
309325

310-
```
326+
~~~php
311327
Bigcommerce::verifyPeer(false);
312-
```
328+
~~~
313329

314330
Connecting through a proxy server
315331
---------------------------------
@@ -318,6 +334,6 @@ In cases where you need to connect to the API through a proxy server, you may
318334
need to configure the client to recognize this. Provide the URL of the proxy
319335
server and (optionally) a port to the useProxy method:
320336

321-
```
337+
~~~php
322338
Bigcommerce::useProxy("http://proxy.example.com", 81);
323-
```
339+
~~~

0 commit comments

Comments
 (0)