Problem implementation API with my shop Prestashop

  • philatelie-lmi77

    19 berichten

    Frankrijk

    You will find below the code that sends us a multitude of errors. Can you tell us what's wrong or confirm that your API is not working right now. We have seen on a forum several messages dating from 3/11/17 related problems similar to those we meet and what worries me is that these problems have already been raised for several months without a solution. has been brought !!
    API used: RESTURL called: Link (http) (the token was obviously filled with the real SECRET token obtained via the call Link (http) .Method: POSTLanguage used: PHPPersion of PHP: 7.0.17Server type: ApacheVersion of Apache: Apache / 2.4.10 (Debian)
    POST argument array obtained via a var_dump ():

    array(2) { ["type"]=> string(10) "fixedPrice" ["item"]=> array(11) { ["id_country"]=> int(1) ["id_category"]=> int(13725) ["fixed_price"]=> float(1.5) ["currency"]=> string(3) "EUR" ["title"]=> string(72) "TEST NE PAS ACHETER - Timbre 913 - Allemagne - Republique Federale, 1980" ["personal_reference"]=> string(10) "PLMI77-230" ["qty"]=> int(1) ["duration"]=> int(28) ["description"]=> string(45) "carte maximum de RFA livrée conforme au scan" ["renew"]=> int(99) ["images"]=> array(1) { [0]=> string(94) " Link (https) " } }}
    Réponse de l’API :

    <?xml version="1.0" encoding="UTF-8"?>
    <Delcampe_Notification>
    <Notification_Token>3d0e9beaa075fb25f91b9605aa2d994d</Notification_Token>
    <Notification_Datetime>2017-11-04 19:56:36</Notification_Datetime>
    <Notification_Data>
    <Headers>
    <Ressource>item</Ressource>
    <Action>POST</Action>
    <Status>400</Status>
    </Headers>
    <body>
    <error>err_item_incorrectIdCategory, err_item_emptyTitle, err_item_incorrectFixedPrice, Ce formulaire ne doit pas contenir de champs supplémentaires</error>
    </body>
    </Notification_Data>
    </Delcampe_Notification>

    The category id is correct and the other parameters too. No additional parameters, basically it's still a copy pasted from the doc on GitHub so good ...

    I therefore ask you to kindly bring me clear and reliable answers, otherwise I will not be able to put my 50,000 ads at home.
    Regards,
    Lionel
  • philatelie-lmi77

    19 berichten

    Frankrijk

    Can you tell me if the code below has errors because I can not install your API.

    private function synchronizeProduct($id_product, $type_action = 'create') {
    $product = new Product($id_product, true, 1, 1);
    $quantity_product = StockAvailable::getQuantityAvailableByProduct($id_product, null, 1);
    $id_category_delcampe = $this->findCategoryMathcOnDelcampe($product->id_category_default);
    $context = Context::getContext()->cloneContext();
    $context->shop = new Shop(1);
    $null = null;
    $price = Product::getPriceStatic((int)$id_product, true, null, 6, null, false, true, 1, false, null, null, null, $null, true, true, $context);
    $image = Image::getCover($id_product);
    $link = new Link();
    $imagePath = ' Link (https) $product->link_rewrite, $image['id_image'], 'home_default');

    if($id_category_delcampe) {
    if($type_action == 'create') {
    $postData = array(
    'type' => 'fixedPrice',
    'item' => array(
    'id_country' => 1,
    'id_category' => (int)$id_category_delcampe,
    'fixed_price' => $price,
    'currency' => 'EUR',
    'title' => "TEST NE PAS ACHETER - ".$product->name,
    'personal_reference' => "PLMI77-".$id_product,
    'qty' => $quantity_product,
    'duration' => 28,
    'description' => $product->description,
    'renew' => 99,
    'images' => array(
    $imagePath
    )
    )
    );

    //echo "<pre>";var_dump($postData);echo "</pre>";die();

    $url = ' Link (http) ;
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POST, true);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
    } elseif($type_action == 'update') {
    $id_product_delcampe = $this->findProductMathcOnDelcampe($id_product);

    if($id_product_delcampe) {
    $postData = array(
    'item' => array(
    'title' => $product->name,
    'personal_reference' => $id_product,
    'qty' => $product->stock_available->quantity,
    'description' => $product->description
    )
    );

    $url = ' Link (http) ;
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($postData) );
    curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    } else {
    $this->synchronizeProduct($id_product, 'create');
    exit();
    }
    }

    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    $xml_response = curl_exec($ch);

    var_dump($xml_response);die();
    }
    }

    private function getDelcampeSecretToken() {
    if(empty($this->secretToken)) {
    $postData = array(
    'apikey' => Configuration::get('DELCAMPE_REST_API_TOKEN')
    );

    $url = ' Link (http) ';
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POST, true);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    $xml_response = new SimpleXMLElement(curl_exec($ch));

    $this->secretToken = (string) $xml_response->Notification_Data->body->token;
    }

    return $this->secretToken;
    }

    private function findCategoryMathcOnDelcampe($id_category_presta) {
    $q = "SELECT id_delcamp_category FROM ps_delcampe_category_match WHERE id_ps_category = ".$id_category_presta;
    $result = Db::getInstance()->getValue($q);

    if($result == 0) {
    return false;
    } else {
    return $result;
    }
    }
  • limilvil-test

    5 berichten

    Frankrijk

    Hi,

    I'm the developer who works for limilvil. Could you, please, answer us...

    We try to implement your REST API on a Prestashop shop but the /item POST call seem to don't work...

    We tried to call your example (available on your Github documentation) but it don't work too... Is your documentation updated ? Link to the related Wiki : Link (https)

    I hasn't any problem with /category call for exemple, the problem is localized on "/item" call...

    Thanks for telling us what's wrong ASAP...

    Best,
    Nicolas
  • Rekening verwijderd
    Rekening verwijderd

    0 berichten

    België

    De informatie is niet meer beschikbaar omdat de rekening van deze gebruiker is verwijderd (AVG)
  • limilvil-test

    5 berichten

    Frankrijk

    I already read this topic but it doesn't solve my problem.

    In this topic, answer is that the category id is a parent category ID. In my case, that's not it ! If I call /category with 13725 in id_parent, your API return an empty response => no sub categories...

    Thanks
  • @kevin
    Beheerder

    102 berichten

    België

    Hi,

    It seems your category_id 13725 is not a category_parent_id.
    The parent_id of the category you want to access is 2637.

    Hope it will help you.

    Have a nice day.
  • limilvil-test

    5 berichten

    Frankrijk

    Hi,

    I know that the id_parent of the 13725 category is 2637 but that's not my question...

    If I understood correctly, it's not possible to add a product to a parent category, only to a category that hasn't any sub categories. That's it ?

    My category: 13725 is not a parent category so I should be able to add a fixed price item on this...

    So, can you PLEASE, answering our question : "What's wrong on the code below" ?

    $postData = array(
    'type' => 'fixedPrice',
    'item' => array(
    'id_country' => 1,
    'id_category' => 13725,
    'fixed_price' => '2.3', //for example
    'currency' => 'EUR',
    'title' => "TEST NE PAS ACHETER - NOM_PRODUIT_TEST",
    'personal_reference' => "PLMI77-34539",
    'qty' => 1,
    'duration' => 28,
    'description' => "Description text bla bla bla",
    'renew' => 99,
    'images' => array(
    " Link (https) "
    )
    )
    );

    $url = " Link (http) " ;
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POST, true);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    $xml_response = curl_exec($ch);

    This call return :

    <?xml version="1.0" encoding="UTF-8"?>
    <Delcampe_Notification>
    <Notification_Token>3d0e9beaa075fb25f91b9605aa2d994d</Notification_Token>
    <Notification_Datetime>2017-11-04 19:56:36</Notification_Datetime>
    <Notification_Data>
    <Headers>
    <Ressource>item</Ressource>
    <Action>POST</Action>
    <Status>400</Status>
    </Headers>
    <body>
    <error>err_item_incorrectIdCategory, err_item_emptyTitle, err_item_incorrectFixedPrice, Ce formulaire ne doit pas contenir de champs supplémentaires</error>
    </body>
    </Notification_Data>
    </Delcampe_Notification>

    Thanks..
  • @kevin
    Beheerder

    102 berichten

    België

    Hi,

    Thank you for your return. It helped us to find the issue.

    It's seems your test account doesn't have a deliveryDestination, an activatedPaymentMethod or/and a descriptionShippingAndHandling. That's why the api returns an error.

    I updated your test account with the parameters mentionned and we will add a new error message for this case asap.

    Could you please try again ?
  • limilvil-test

    5 berichten

    Frankrijk

    Hi,

    It works, thanks ! :veryhappy:

    Yes, a new error will make your API more simply to debug. You should add a note on the github documentation on this subject ;)

    Best
  • @kevin
    Beheerder

    102 berichten

    België

    Hi,

    Glad to have been able to help you.
    Have a nice day.
  • limilvil-test

    5 berichten

    Frankrijk

    Hello, we have completed the tests. Now we can not insert ads on our usual identifier (Limilvil), only on Limilvil-test and Limilvil-dev. We need an API key to be able to send our products to the Limilvil account. Thank you
  • @kevin
    Beheerder

    102 berichten

    België

    Hi,

    "limilvil-test" is your test account.
    "limilvil-dev" is your account linked to your main account.
    So you can use the api from your pseudo "-dev" to send products to your main account.

    Have a nice day.
  • philatelie-lmi77

    19 berichten

    Frankrijk

    Yes, but when I send products in limilvil-dev, they are not visible in my current sales on limilvil !! The settings of the -dev account are not the same as on limilvil. Is there anything to be done so that the products sent on limilvil-dev are visible on limilvil? Thank you for your help.
  • @kevin
    Beheerder

    102 berichten

    België

    Hello,

    Indeed, there was a link problem between your different API accounts.
    I fixed it. You can test it should be ok.

Word lid van de verzamelaars-community!

Registreren Aanmelden