Lulu Developer Forums

API Development Community

RSS Feed

PHP and update

    • eset
    • Topic created 2 years ago

    hi,

    I am struggling a bit to get a project to update. I'm using PHP with the following (after authenticating correctly): $url = "https://apps.lulu.com/api/publish/v1/update/id/".$content_id; $data = array('publisher' => $metadata, 'api_key' => $apikey, 'auth_token' => $authToken, 'auth_user' =>$authUser); $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); print_r($response); die;

    $metadata is the unaltered json string with the project info obtained using the lulu api.

    However I get the response : {"error_value": "project", "error_type": "KeyError", "additional": "?"}

    Any idea what I am doing wrong?

    adam

    {"error_value": "project", "error_type": "KeyError", "additional": "?"}

    Message edited by eset 2 years ago

  1. eset2 years ago

    sorry, here is a better formatted code block

    1. $url = "https://apps.lulu.com/api/publish/v1/update/id/".$content_id;
    2. $data = array('publisher' => $metadata, 'api_key' => $apikey, 'auth_token' => $authToken,'auth_user' => $authUser);
    3. $ch = curl_init($url);
    4. curl_setopt($ch, CURLOPT_POST, true);
    5. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    7. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    8. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    9. $response = curl_exec($ch);
    10. print_r($response);
  2. Josiah Gore2 years ago

    You likely simply need to change 'publisher' key to 'project' in the dictionary you are POSTing. The API is looking for 'project' for the data with which to update, which is why you are seeing a KeyError when it is not found.

  3. eset2 years ago

    ah..thanks. i did that now and it still returns the same error.

  4. eset2 years ago

    actually the error i get now is:

    {"error_value": "content_id", "error_type": "KeyError", "additional": "?"}

    the code I am using is :

    1. $url = "https://apps.lulu.com/api/publish/v1/update/id/".$content_id;
    2.  $data = array('project' => stripslashes($metadata), 'api_key' => $apikey, 'auth_token' => $authToken,'auth_user' => $authUser);
    3. $ch = curl_init($url);
    4. curl_setopt($ch, CURLOPT_POST, true);
    5. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    7. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    8. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    9. $response = curl_exec($ch);
    10. print_r($response);
  5. Josiah Gore2 years ago

    Could you post a dump of the $metadata structure? It's hard to know where the problem is parsing the structure without seeing how the data is being supplied.

  6. eset2 years ago

    sure, this is the raw data what goes into $metadata:

    {"project": {"bibliography": {"category": 0, "publisher": "", "copyright_citation": "", "description": "", "license": "Standard Copyright License", "title": "newscoop tester", "language": "EN", "copyright_year": 2011, "edition": "", "country_code": "US", "authors": [{"first_name": "adam", "last_name": "hyde"}], "keywords": []}, "program_code": null, "access": "private", "drm": false, "allow_ratings": true, "project_type": "softcover", "distribution": ["lulu_marketplace"], "content_id": 10563289, "physical_attributes": {"color": false, "trim_size": "US_TRADE", "binding_type": "perfect", "paper_type": "regular"}, "pricing": [{"total_price": 0.79000000000000004, "product": "download", "royalty": 0, "currency_code": "EUR", "discount_percent": 0}, {"total_price": 9.1400000000000006, "product": "print", "royalty": 0, "currency_code": "EUR", "discount_percent": 0}]}}

  7. Josiah Gore2 years ago

    Try removing the outer dictionary, using 'project' only as the key in the POST data key value pairs rather than as a key in the JSON dictionary. So, instead of passing

    api_key=XXX&auth_token=XXX&project={"project": { "bibliography": {...}, ... }
    

    simply pass in

    api_key=XXX&auth_token=XXX&project={"bibliography": {...}, ... }
    
  8. eset2 years ago

    thanks!

    ...seems to be the answer. Now I went through a other 'missing field' errors but stuck on: {"error_value": "Missing or invalid delivery id", "error_type": "LInvalidProductException"}

    any idea what that is?

    :)

    adam

  9. eset2 years ago

    actually, i found the error...something to do with incorrect info in the product download pairs...thanks a lot for your help :)

  10. Josiah Gore2 years ago

    I'm glad you were able to figure it out. Let me know if you have any more questions.

[ Page 1 of 1 ]