API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

[SOLVED] Product_Create the product group may not be null

0
HI, I'm trying to create a product, but I can't get it to see the ProductGroup
But i get an error

Fatal error Uncaught SoapFault exception soapClient EconomicApiExceptionsValidationException(E04010) The product group may not be null {id=963763423} in /opt/lampp/htdocs/PHP/test1php43 Stack trace #0 internal function SoapClient-__call('Product_Create', Array) #1 /opt/lampp/htdocs/PHP/test1php(43) SoapClient-Product_Create(Array) #2 {main} thrown in /opt/lampp/htdocs/PHP/test1php on line 43

This is the code I use

$ProductGroup = $client-ProductGroup_FindByName(array('name' = 'Varor'))-ProductGroup_FindByNameResult-ProductGroupHandle;
print($ProductGroup-Number);
?br/?
$client-Product_Create(array(
            'number' = 'ART',
            'productGroup' = $ProductGroup,
            'name' = 'APITest'));// Line 43

I tried writing 'ProductGroup' and 'productgroup' and 'ProductGroupHandle', still recives the same error.
created Jun 26, 2010 by Madman
0% Accept Rate
Q 5 A 13 C 0

2 Answers

0
I also tried to use a similar code that is used in the list_debators.php the is included in the Dev kit.

        try
        {
            $productGroupHandels = $client-productGroup_GetAll()-ProductGroup_GetAllResult-ProductGroupHandle;
            $firstProductGroup = $ProductGroupHandels0;
            $newProductHandle = $client-Product_Create(array(
                'number' = 'ART',
                'ProductGroupHandle' = $firstProductGroup,
                'name' = 'APITest2'))-Product_CreateResult;
                print('Product was Created');
        }
        catch(Exception $exception)
        {
            print(pbCould not create product/b/p);
            print(pi  $exception-getMessage()  /i/p);
        }

All that did was to give a nicer looking error.

E-conomic API Test log

Connected

Could not create product

EconomicApiExceptionsValidationException(E04010) The product group may not be null {id=967006210}
Disconnected

I mailed the API guys, but they don't know PHP, so they can't really help me they said.
I also mailed another contact, but he couldnt figuer out what was wrong either.
Bellow is the complete file, with login details edited.

html
head
titleE-conomic API Test/title
/head
body
strongE-conomic API Test log/strongbr/br/
?php

//Functions
//Function for connecting to e-conomic
function ecConnect($agNr,$user,$pass) {
    $apiUrl = 'https//wwwe-conomiccom/secure/api1/EconomicWebserviceasmx?WSDL';
    $client = new SoapClient($apiUrl,array(trace = 1, exceptions = 1)); //Line 6
    $client-Connect(array(
        'agreementNumber' = $agNr,
        'userName' = $user,
        'password' = $pass));
    print('Connectedbr/');
    return $client;
}

//Functions for disconnecting from e-conimic
function ecDisconnect($client) {
    $client-Disconnect();
    print('Disconnectedbr/');
}

//Account Details
$agreementNumber = 12345;
$username = 'name';
$password = 'password';

//Connect to ec
$client = ecConnect($agreementNumber,$username,$password);

        try
        {
            $productGroupHandels = $client-productGroup_GetAll()-ProductGroup_GetAllResult-ProductGroupHandle;
            $firstProductGroup = $ProductGroupHandels0;
            $newProductHandle = $client-Product_Create(array(
                'number' = 'ART',
                'ProductGroupHandle' = $firstProductGroup,
                'name' = 'APITest2'))-Product_CreateResult;
                print('Product was Created');
        }
        catch(Exception $exception)
        {
            print(pbCould not create product/b/p);
            print(pi  $exception-getMessage()  /i/p);
        }
/*
//$ProductGroup = $client-ProductGroup_FindByNumber(array('number' = 1));//-ProductGroup_FindByNumberResult;//-ProductGroupHandle;
$ProductGroup = $client-ProductGroup_FindByName(array('name' = 'Varor'))-ProductGroup_FindByNameResult-ProductGroupHandle;
//$debtorGroupHandles = $client-debtorGroup_GetAll()-DebtorGroup_GetAllResult-DebtorGroupHandle;
$GroupHandles = $client-ProductGroup_GetAll()-ProductGroup_GetAllResult-ProductGroupHandle;
//$firstGroup = $GroupHandles0-Number;
print($ProductGroup-Number);
?br/?
$client-Product_Create(array(
            'number' = 'ART',
            'ProductGroupHandle' = $ProductGroup-Number,
            'name' = 'APITest',
                        ));

*/
// Disconnect from ec
ecDisconnect($client);
?
/body
/html
answered Jun 29, 2010 by Madman
0
It has been solved.
Working code

// Get Product Group
$ProductGroupHandles = $client-ProductGroup_GetAll()-ProductGroup_GetAllResult-ProductGroupHandle;
//print_r($ProductGroupHandles);
$firstProductGroup = $ProductGroupHandles0;

//Create Product
$client-Product_Create(array(
    'number' = 'ABC123',             
    'name' = 'Produktnamn',
    'productGroupHandle' = $firstProductGroup));

$productHandle = $client-Product_FindByNumber(array(
    'number' = 'ABC123'))-Product_FindByNumberResult;

$client-Product_SetSalesPrice(array(
    'productHandle' = $productHandle,
    'value' = '100'))-Product_FindByNumberResult;

$client-Product_SetIsAccessible(array(     
    'productHandle' = $productHandle,
    'value' = 1))-Product_FindByNumberResult;


The problem has been that I only had one Product group.
If You have only 1 product group print_r line in code will show
stdClass Object ( [Number] = 1 )
and there for $firstProductGroup = $ProductGroupHandles[0]; is null.
If there is only one product group it has to be $firstProductGroup = $ProductGroupHandles;
If more then 1 productgroup, it will return
Array ( [0] = stdClass Object ( [Number] = 1 ) [1] = stdClass Object ( [Number] = 2 ) )
If more then 1, most likely all my posted code example will work, but it's not confirmed
But the one above work, and set the wanted data
answered Jun 29, 2010 by Madman
Visma e-conomic A/S
...