bigcommerce rest api v3 php

494 Views Asked by At

I have to implement bigcommerce API integration with PHP and I am trying to use the official library from https://github.com/bigcommerce/bigcommerce-api-php

and I am not even able to start step 1 here.

Issues:

Basic Auth method

Bigcommerce::configure(array(
    'store_url' => 'https://store.mybigcommerce.com',
    'username'  => 'admin',
    'api_key'   => 'd81aada4xc34xx3e18f0xxxx7f36ca'
));

So the question here is how to get a username? bigcommerece user only created using email address so how to get username here?

OAuth method

In order to obtain the auth_token you would consume Bigcommerce::getAuthToken method

$object = new \stdClass();
$object->client_id = 'xxxxxx';
$object->client_secret = 'xxxxx;
$object->redirect_uri = 'https://app.com/redirect';
$object->code = $request->get('code');
$object->context = $request->get('context');
$object->scope = $request->get('scope');

$authTokenResponse = Bigcommerce::getAuthToken($object);

Bigcommerce::configure(array(
    'client_id' => 'xxxxxxxx',
    'auth_token' => $authTokenResponse->access_token,
    'store_hash' => 'xxxxxxx'
));

here the question is what is the $request variable? also, redirect_uri is the bigcommerce store URL or my site URL?

Please can anyone help to get started with this?

1

There are 1 best solutions below

0
On

It's because that library is a bit out of date with how api accounts are managed. For the basic auth you would use "legacy accounts". You can just use the OAuth method without the oAuth flow (assuming you're trying to connect to your own store, not create an app).

Just the following will work:

Bigcommerce::configure(array(
    'client_id' => 'client-id',
    'auth_token' => 'access-token',
    'store_hash' => 'store-hash'
));

You should get these after creating a user in the dashboard (you can ignore the secret for this use case)