API help

Comments

7 comments

  • Avatar
    Matthew Sikorski

    I'm not sure if it matters, but I am using the downloaded version on my own server.

  • Avatar
    Chris Muench

    It looks ok but start with the below working example and keep modifying it (The code below is tested)

    <?php

    //////////////////////////////////////////////////////////

    $api_base_url = 'http://localhost/phppos/PHP-Point-Of-Sale/index.php/api/v1/';

    $api_key = 'k4koggkc0k40k8w0kkc00gckkcs8kw888sskks0o';

    ///////////////////////////////////////////////////////////







    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, $api_base_url.'items');

    curl_setopt($curl, CURLOPT_HTTPHEADER, array(

        'x-api-key:'.$api_key,

    'accept: application/json',

        ));

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 




    $result = json_decode(curl_exec($curl), TRUE);

    echo '<pre>';

    var_dump($result);

    echo '</pre>';
  • Avatar
    Matthew Sikorski

    Thank you for that. The problem was FOLLOWLOCATION (I had set to false).

    Now I just need to figure out what fields I need to pass to create a purchase order with specific variations of items.

  • Avatar
    Matthew Sikorski

    I've been beating my head against this all day and can't get it to create a purchase order with the variation rather than the parent item. Here is the code for my call. Please let me know what I'm doing wrong.


    $po = array('mode' => 'receive',
    'suspended' => 1,
    'is_po' => true,
    'location_id' => 1,
    'employee_id' => 1,
    'register_id' => 1,
    'comment' => 'testpo',
    'supplier_id' => 348);
    $item = array( 'quantity' => 5,
    "item_variation_id"=>62519,
    'item_id'=>6882,
    "name"=>'3" SHORTY CNP 530 YL',
    "item_number"=> "UA/1264660-530-YLG",
    "product_id"=> "UA/1264660-530-YLG",
    "unit_price"=> 19.99,
    "cost_price"=> 8.80,
    "SIZE"=>"YLG",
    "COLOR"=>"530",
    );
    $po['cart_items'][] = $item;
    echo '<pre>'; print_r($po); echo '</pre>';

    echo "Adding PO to the POS...";
    $make_call = callAPI('POST', 'receivings/', json_encode($po));
    $response = json_decode($make_call, true);
    echo '<pre>'; var_dump($response); echo '</pre>';

  • Avatar
    Chris Muench

    You will need to perform debugging steps to figure out the exact error.
    Open up index.php in the phppos root folder:

    FIND:
    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production’);

    REPLACE:
    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : ‘development’);

    open application/config/database.php

    FIND:
    $db['default']['db_debug'] = FALSE;

    REPLACE:
    $db['default']['db_debug'] = TRUE;

    Then see the errors.

    Do NOT forget to undo these changes afterwords.

  • Avatar
    Matthew Sikorski

    There are no errors. The purchase order gets saved, but it has the wrong item. It has the "parent" item rather than the variation that I specified.

  • Avatar
    Chris Muench

    Found a bug and just patched the code. Will be available in 30-60 minutes to download.

Please sign in to leave a comment.