Problem with getting the sales price of item in Exact Online

727 views Asked by At

I am trying to use the exact online API, my web application can connect with the API and create Accounts, Items and all the other things.

But now, inside off my web application I need those Accounts and Items etcetera, I got it done to select all the Items and import those into my database, but I can't find the SalesPrice of an Item, only the 'CostPriceNew' and 'CostPriceStandard'!

After a while searching, I found out that there is another class called: ItemDetailsByID inside this class i found SalesPrice

At first i get an error: Fatal error: Uncaught TypeError: Argument 1 passed to Picqer\Financials\Exact\ItemDetailsByID::get() must be of the type array, string given

This is the code I used: `

//Retrieve items
$items = new \Picqer\Financials\Exact\Item($connection);
$result = $items->get();

foreach ($result as $item) {

    try {

        $ItemDetails = new \Picqer\Financials\Exact\ItemDetailsByID($connection);
        $result1 = $ItemDetails->get($item->ID);

        foreach ($result1 as $ItemDetail) {

            var_dump($ItemDetail);

        }
        
    } catch (\Exception $e) {

        echo json_encode(array(get_class($e) . ' : ' . $e->getMessage()));

    }

}

`

After reading the documentation from exact online i still don't managed to use this class.. now I am getting this error: ["Picqer\\Financials\\Exact\\ApiException : Error 400: Bad Request - Error in query syntax."]

After the first error I changed my code $result1 = $ItemDetails->get($item->ID);

into

$result1 = $ItemDetails->get(["eq guid" => "'$item->ID'"]);

I have tried multiple array keys like: 'eq guid', 'Edm.Guid', 'guid', 'id' but I stil get the error.

I hope that someone can help me or pointing me into the right direction.

2

There are 2 answers

0
Hieast On

Your question is not very clear, I try to give you a general suggestion before you add more info.

log the http protocol and compare with the doc, if you do not have a client log, you can send your request to httpbin.org(be careful with your password and other personal piracy using third party service), just like https://httpbin.org/get?itemId=guid'00000000-0000-0000-0000-000000000000'&$select=Code,SalesCurrency,SalesPrice.

It will print request info, this can help to debug

{
    "args": {
        "$select": "Code,SalesCurrency,SalesPrice",
        "itemId": "guid'00000000-0000-0000-0000-000000000000'"
    },
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate, br",
        "Cache-Control": "no-cache",
        "Host": "httpbin.org",
        "User-Agent": "PostmanRuntime/7.26.5",
    },
    "origin": "a.b.c.d",
    "url": "https://httpbin.org/get?itemId=guid'00000000-0000-0000-0000-000000000000'&$select=Code,SalesCurrency,SalesPrice"
}
0
Dennis van Schaik On

You dont want to list all item prices, so instead of using get, you should use find. Since you only get one result, after that you can directly use the returned object:

$ItemDetails = new \Picqer\Financials\Exact\ItemDetailsByID($connection);
$result1 = $ItemDetails->find($item->ID);
var_dump($result1->SalesPrice);