@makoso commented an hour ago
Hi, i have today to test REST API, and two methods not works.
The update method return 500.
the createNew method return 405, invalid method, it's ok? the POST method isn't visible on methods allowed, but is used in example, can You tell me how to add new record from REST now? it is possible?
@bpabiszczak
Member
bpabiszczak commented just now
If you have 500, you must check apache logs... https://yetiforce.com/en/administrator-documentation/errors/227-apache-500-internal-server-error-2.html
@makoso check out the code that made migoi, I helped me understand the API
https://github.com/YetiForceCompany/YetiForceScripts/tree/master/YetiREST
@bpabiszczak With debug REST i can see this error:
updating recordREST Error (200): 2: Invalid argument supplied for foreach() in api/webservice/Portal/BaseModule/Record.php, line 107
Array
(
[status] => 0
[error] => Array
(
[message] => 2: Invalid argument supplied for foreach() in /api/webservice/Portal/BaseModule/Record.php, line 107
[code] => 200
)
)
@WalterLuis im working on this files, just coppy setup user, passwords and try run.
Thanks for reply
Version of the system?
4.0.0 new install, tested other functions of REST working well except this two, i see changes on developer branch, but idk, i should waiting for next update?
@WalterLuis @makoso
the YetiREST is tested and runs against latest YetiForce API from 'developer' branch, so e.g. for creating the record no more recordData subkey is needed.
Thanks, i update this file: https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/api/webservice/Portal/BaseModule/Record.php and it works.
Can be closed.
@migoi Can You help me with add products to invoice? I cant create good request how should be structured data for this request? I tried with fields like 'seq1', 'inventoryItemsNo' it still creating invoice but without products assigned to this invoice.
Hi @makoso,
uff, never tried before. How I would try to figure out that one:
1st try)
Create Invoice with products from webinterface. Next fetch this records via API. You will see what fields and values (and with what kind of structure the data tree is build)
2nd try)
Use the YetiPortal and have a look if there is a possibility to create invoice (invoice yes but not with products ....). You can activate some sort of debugger in page footer - that will show the request and response used in config.php.
~php
...
$config['debugApi'] = true;
...
~
You will read something like
~~~php
[inventory] => Array
(
[0] => Array
(
[name] => Fake1
[unit] =>
[subunit] =>
[qty] => 1
[price] => 12,00
[total] => 12,00
[net] => 12,00
[tax] => 0,00
[gross] => 12,00
[comment1] =>
[currency] => Euro
[taxmode] => LBL_GROUP
)
[1] => Array
(
[name] => Fake2
[unit] =>
[subunit] =>
[qty] => 1
[price] => 34,00
[total] => 34,00
[net] => 34,00
[tax] => 0,00
[gross] => 34,00
[comment1] =>
[currency] => Euro
[taxmode] => LBL_GROUP
)
)
~~~
so provide them as array to the "inventory" key
3rd try)
Cry for help in an issue like this and hopefully @bpabiszczak or @mariuszkrzaczkowski will answer :smiley:
Hi again,
Your answer isn't helpfully.
Its output created by this code:
if ($recordModel->getModule()->isInventory()) {
$rawInventory = $recordModel->getInventoryData();
$inventory = [];
$inventoryField = \Vtiger_InventoryField_Model::getInstance($moduleName);
$inventoryFields = $inventoryField->getFields();
foreach ($rawInventory as $row) {
$inventoryRow = [];
foreach ($inventoryFields as $name => $field) {
$inventoryRow[$name] = $field->getDisplayValue($row[$name]);
}
$inventory[] = $inventoryRow;
}
}
in Api\Portal\BaseModule\Record this structure cant be used in insert method...
The structure of insert is
...
'qty1' => 1,
'price1' => '12,00',
'total1' => '12,00',
...
'qty2' => 1,
'price2' => '12,00',
'total2' => '12,00',
...
'inventoryItemsNo' => 2
and it will be executed in method initInventoryData()
public function initInventoryData()
{
\App\Log::trace('Entering ' . __METHOD__);
$moduleName = $this->getModuleName();
$inventory = Vtiger_InventoryField_Model::getInstance($moduleName);
$fields = $inventory->getColumns();
$summaryFields = $inventory->getSummaryFields();
$inventoryData = $summary = [];
if (isset($this->inventoryRawData)) {
$request = $this->inventoryRawData;
} else {
// WS call going here
$request = AppRequest::init();
}
// request lost this param...
if ($request->has('inventoryItemsNo')) {
$numRow = $request->get('inventoryItemsNo');
for ($i = 1; $i <= $numRow; $i++) {
if (!$request->has(reset($fields)) && !$request->has(reset($fields) . $i)) {
continue;
}
$insertData = ['seq' => $request->get('seq' . $i)];
foreach ($fields as &$field) {
$insertData[$field] = $inventory->getValueForSave($request, $field, $i);
}
$inventoryData[] = $insertData;
}
$prefix = 'sum_';
$inventoryFields = $inventory->getFields();
foreach ($summaryFields as &$fieldName) {
if ($this->has($prefix . $fieldName)) {
$value = $inventoryFields[$fieldName]->getSummaryValuesFromData($inventoryData);
$this->set($prefix . $fieldName, $value);
}
}
}
$this->inventoryData = $inventoryData;
\App\Log::trace('Exiting ' . __METHOD__);
}
placed in Vtiger_Record_Model
my request lost this required param inventoryItemsNo and next code isn't executed, when i test it with comment check of this param and assign it to 1 my call is stoping on:
if (!$request->has(reset($fields)) && !$request->has(reset($fields) . $i)) {
I want get answer on this two questions:
I cant find good method to add this products to the invoice
silence is golden?
a said before: I cant help and I dont know if and when the API will be extended for processing SubItems. Someone from YetiForce could give that type of information.
In class Vtiger_Save_Action->saveRecord()
i have change to
if($recordModel->getModule()->isInventory()){
$recordModel->save($request);
} else {
$recordModel->save();
}
in Vtiger_Record_Model i have change methods initInventoryData and save to accept $request and default is false
and inside method save change $this→initInventoryData(); to $this→initInventoryData($request);
and inside initInventoryData
if (isset($this->inventoryRawData)) {
$request = $this->inventoryRawData;
} elseif($request !== false) {
} else {
$request = AppRequest::init();
}
now it works for me.
thanks for help.
create was not working until i changed yetirest.php
Line 326 from $type = 'POST'; to $type = 'PUT';
post = create rekord
put = edit rekord
Yep i know but had to come up with a quicky will furthur test and provide feedback
Getting REST Error (405): Invalid method with POST
Works correctly
