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

How do I create a product? How do I search for a product? #75

Closed
Lollichkeit opened this issue Oct 6, 2023 · 2 comments
Closed

How do I create a product? How do I search for a product? #75

Lollichkeit opened this issue Oct 6, 2023 · 2 comments

Comments

@Lollichkeit
Copy link

Lollichkeit commented Oct 6, 2023

My goal is:
Reading out whether the product is available and if not, then creating it, but I already have an error while creating it.

My code:

...
$product = new Product;
$title = new TranslatableText;
$title->text = 'Test';
$title->languageCode = 'de';

$product->title 		= $title;
$product->sku		= 'test';
$product->soldAmount	=  99.99;

print_r($product);

$test = $client->createProduct($product);
print_r($test);
...

My Error:
Fatal error:
Uncaught GuzzleHttp\Exception\ClientException:
Client error: POST https://app.billbee.io/api/v1/products resulted in a 400 Bad Request response: {"Message":"Die Anforderung ist ungültig.","ModelState":{"model.Title.text":["Cannot deserialize the current JSON objec (truncated...) in .../vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 .../vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 .../vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response)) #2
.../vendor/guzzlehttp/promises/src/Promise.php(153):
GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL) #3
.../ap in .../vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

@Lollichkeit Lollichkeit changed the title Wie erstelle ich ein Produkt? Wie such ich nach ein Produkt? How do I create a product? How do I search for a product? Oct 9, 2023
@devtronic
Copy link
Member

As you can see in Product.php, the title is an array of TranslatableText.

In your specific case this should work:

// ...
$product = new Product;
$title = new TranslatableText;
$title->text = 'Test';
$title->languageCode = 'de';

$product->title 	= [$title]; // added square brackets
$product->sku		= 'test';
$product->soldAmount	=  99.99;

print_r($product);

$test = $client->createProduct($product);
print_r($test);
// ...

@Lollichkeit
Copy link
Author

Lollichkeit commented Oct 25, 2023

Thanks again for your help. I am working on the problem again and I keep getting the error 500 Internal Server Error.
Can you help me please?

Uncaught GuzzleHttp\Exception\ServerException: Server error: 'POST https://app.billbee.io/api/v1/products' resulted in a '500 Internal Server Error' response:

@devtronic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants