Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating new Article/Product result in a 500 Internal Server Error. #21

Closed
TiBianMod opened this issue Nov 3, 2019 · 3 comments
Labels

Comments

@TiBianMod
Copy link

@TiBianMod TiBianMod commented Nov 3, 2019

Like the Title indicates, creating new Article/Product result in a 500 Internal Server Error.

// Let's keep the example very simple.
use BillbeeDe\BillbeeAPI\Client;

$user = Config::get('BILLBEE_USER');
$apiPassword = Config::get('BILLBEE_API_PASSWORD');
$apiKey = Config::get('BILLBEE_API_KEY');

$client = new Client($user, $apiPassword, $apiKey);

// Based on the server responses the minimum field requirement are the following fields.
$data = [
    'form_params' => [
        'Title' => 'Product Title',
        'VatIndex' => 1,
        'Price' => 5.29,
        'Vat1Rate' => 0,
        'Vat2Rate' => 0,
        'Type' => 1,
        // Another issue: will not accept boolean (This is the reason why i use string here.)
        'IsDigital' => 'false', 
        // Another issue: will not accept boolean (This is the reason why i use string here.)
        'IsCustomizable' => 'false',
    ]
];

$client->post('products', $data);

Here is the response from the server.

Fatal error: Uncaught GuzzleHttp\Exception\ServerException: Server error: `POST https://app.billbee.io/api/v1/products` resulted in a `500 Internal Server Error` response: {"ErrorMessage":"Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.","ErrorCode":8,"Data":null}

Is ok if i open another issues here?

@devtronic devtronic added bug enhancement and removed bug labels Nov 3, 2019
@devtronic

This comment has been minimized.

Copy link
Member

@devtronic devtronic commented Nov 4, 2019

This endpoint is not implemented in the SDK at the moment. You can extend the client class and write your own method:

<?php

use BillbeeDe\BillbeeAPI\Client;
use BillbeeDe\BillbeeAPI\Model\Product;
use BillbeeDe\BillbeeAPI\Model\TranslatableText;
use BillbeeDe\BillbeeAPI\Response\BaseResponse;

$user = Config::get('BILLBEE_USER');
$apiPassword = Config::get('BILLBEE_API_PASSWORD');
$apiKey = Config::get('BILLBEE_API_KEY');

class MyClient extends Client
{
    public function createProduct(Product $product)
    {
        return $this->requestPOST(
            'products', // Products endpoint
            $this->jom->serialize($product), // Serialize the product to json
            BaseResponse::class // response class
        );
    }
}


$myClient = new MyClient($user, $apiPassword, $apiKey);

$myProduct = new Product();
$myProduct->title = [new TranslatableText('Product Title', 'DE')];
$myProduct->vatIndex = 1;
$myProduct->price = 5.29;
$myProduct->stockReduceItemsPerSale = 1.0;
$myProduct->isDigital = false;
$myProduct->isCustomizable = false;

// This fields have wrong values in the current version of the SDK so we need to change them
$myProduct->stocks = [];
$myProduct->weight = 0;
$myProduct->weightNet = 0;
$myProduct->unitsPerItem = 1.0;
$myProduct->soldSumGross = 0.0;
$myProduct->soldSumNet = 0.0;
$myProduct->soldSumNetLast30Days = 0.0;
$myProduct->soldSumGrossLast30Days = 0.0;
$myProduct->soldAmountLast30Days = 0.0;

var_dump($myClient->createProduct($myProduct));
@devtronic

This comment has been minimized.

Copy link
Member

@devtronic devtronic commented Nov 15, 2019

The createProduct call will be available in the next version of the SDK

@devtronic devtronic closed this Nov 15, 2019
@TiBianMod

This comment has been minimized.

Copy link
Author

@TiBianMod TiBianMod commented Nov 15, 2019

Very Nice news, Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.