PHP

How to add item and items under category in Quickbooks online API || Sample code in Laravel PHP

  • Neel Bhardwaj

  • 18-Jan-2022

  • 0 comments

  • 114

First create connection with quickbook online with oauth2

$dataService = DataService::Configure(array(
    'auth_mode' => 'oauth2',
    'ClientID' => '****************',
    'ClientSecret' => ''****************',
    //get the refresh token from session or database
    'refreshTokenKey' => '****************',
    'QBORealmID' => '****************',
    'baseUrl' => "development/production"
));

$OAuth2LoginHelper = $dataService->getOAuth2LoginHelper();
$refreshedAccessTokenObj = $OAuth2LoginHelper->refreshToken();
$this->dataService->updateOAuth2Token($refreshedAccessTokenObj);

To get the new access token and refresh token

$accessToken = $refreshedAccessTokenObj->getAccessToken();
$refreshTokenValue = $refreshedAccessTokenObj->getRefreshToken();


For create item/Product and service under item category

$category_data = [
    "SubItem" => false,
    "Name" => 'Category Name', 
    "Type" => "Category",
    "IncomeAccountRef"=> [ 
        "value"=>  1
    ]
];

$create_category = Item::create($category_data);
$categoryRequestObj = $this->dataService->Add($create_category);

Sample code For create item under category. 
NOTE : In which define ParentRef is category ID and SubItem = true

$item_data = [
    "SubItem" => true,
    "Name" => 'Item Name', 
    "Type" => "Service",
    "IncomeAccountRef"=> [ 
        "value"=>  1
    ],
    "ParentRef"=> $categoryRequestObj->Id
];

$create_category = Item::create($item_data);
$this->dataService->Add($create_category);

"Programming isn't about what you know,
it's about what you can figure out.”
Chris Pine

Neel Bhardwaj

A full stack developer. I have a Passion for Creating Clean, Beautiful, Interactive, Minimalistic, Responsive and User Friendly website, Developed by Modular, Scalable and Functional Code.

Recent comments

Leave a reply