Lulu Developer Forums

API Applications

RSS Feed

Unable to create Project - Using PHP cURL

    • Raja
    • Topic created 3 years ago

    Hi Ryan,

    Below is the error i got when i hit the project create(https://apps.lulu.com/api/publish/v1/create) URL via PHP cURL.

    1. Array
    (
    [error_value] => Extra data: line 2 column 19 - line 36 column 1 (char 20 - 1268)
    [error_type] => ValueError
    [additional] => ?
    )

    following is the input i had given

    $create_input ='{
    "project_type": "hardcover",
    "bibliography": {
    "title": "Books...With Jackets",
    "authors": [{"first_name": "arthur", "last_name": "the author"}],
    "category": 1,
    "description": "read it, you\'ll like it",
    "keywords": ["cat and dog", "pickle"]
    "edition": "First",
    "copyright_year": 2000,
    "copyright_citation": "by Arthur Author",
    "publisher": "Lulu.com",
    "license": "Public Domain",
    "language": "EN",
    "country_code": "US",
    },
    "file_info": {
    "cover": [{"mimetype": "application/pdf", "filename": "cover2.pdf"}],
    "contents": [{"mimetype": "application/pdf", "filename": "contents.pdf"}]
    },
    "program_code": "",
    "access": "public",
    "distribution": [],
    "allow_ratings": false,
    "isbn": { "intent": "assigned" },
    "physical_attributes": {
    "color": false,
    "trim_size": "SIZE_825x1075",
    "binding_type": "casewrap-hardcover",
    "paper_type": "regular"
    },
    "pricing": [
    {"total_price": 15.0, "product": "download", "currency_code": "EUR"},
    {"total_price": 39.95, "product": "print", "discount_percent": 10, "currency_code": "EUR"}
    ]
    }
    ';

    $ch3 = curl_init();
    curl_setopt($ch3, CURLOPT_URL, 'https://apps.lulu.com/api/publish/v1/create');

    $post3 = array(
    "api_key" => $api_key,
    "auth_user" => $auth_user,
    "auth_token" => $authToken,
    "project" => $create_input
    );
    curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch3, CURLOPT_POST, true);
    curl_setopt($ch3, CURLOPT_VERBOSE, true);
    curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch3, CURLOPT_POSTFIELDS, $post3);

    $response3 = curl_exec($ch3);
    curl_close ($ch3);

    echo '<pre>';
    $response3 = json_decode($response3, true);
    print_r($response3);

    Kindly clarify my doubts and let me know the absolute way to get it done. I'm struck in this API for past 1 week.

    Looking forward for the result.

    Thanks,
    Raja

    Message edited by Raja 3 years ago

  1. Josiah Gore3 years ago

    Error of this type (generally saying things like "Extra data", "Expecting property name", "Expecting , delimiter") are caused by badly formatted JSON. In the JSON you've provided above,

    "keywords": ["cat and dog", "pickle"]

    should have a comma at the end, and

    "country_code": "US",

    should _not_ have a comma, as it is followed by the } closing the dictionary structure.

    Let me know if this helps.

[ Page 1 of 1 ]