Announcement
Collapse
No announcement yet.
Assistance regarding API results?
Collapse
X
-
Hey,
Try this instead:
PHP Code:$list = json\retrieve(workflow\lastHttpResponseBody());
$i = 0;
while ($i < array\length($list)) {
$item = array\at($list, $i);
$id = object\get($item, 'id');
if (!record\exists('YOUR_ENTITY_TYPE', 'id=', $id)) {
record\create('YOUR_ENTITY_TYPE', 'id', $id);
}
$i = $i + 1;
}
-
You just have to loop through the ids and compare them to existing ones in your db and create new ones, below is an example:
PHP Code:$list = json\retrieve(workflow\lastHttpResponseBody());
$i = 0;
while ($i < array\length($list)) {
$item = array\at($list, $i);
$id = object\get($item, 'id');
if (record\exists('YOUR_ENTITY_TYPE', 'id=', $id)) {
continue;
}
record\create('YOUR_ENTITY_TYPE', 'id', $id);
$i = $i + 1;
}
- Likes 1
Leave a comment:
-
Let's say I have 8000 IDs in my JSON file that I initially created using "record/create." After 2 days, my JSON file contains 8200 IDs. How can I add only the additional 200 IDs without it recreating all 8200 IDs and ensuring that it checks for existing records with the same name?
Leave a comment:
-
On v8.0.4
Code:$list = json\retrieve(workflow\lastHttpResponseBody()); $i = 0; while ($i < array\length($list)) { $item = array\at($list, $i); $userId = object\get($item, 'userId'); $lastName = object\get($item, 'lastname'); $firstName = object\get($item, 'firstname'); record\create('Lead', 'firstName', $firstName, 'lastName', $lastName, 'userId', $userId); $i = $i + 1; }
- Likes 2
Leave a comment:
-
I used this but I get error
$data = json\encode($_lastHttpResponseBody, true);
$userId = object\get($data, 'userId');
description = $userId
[2023-10-27 19:41:38] ERROR: Workflow[6535a3db68e8691bd]: Action failed [executeFormula] with cid [3], details: function: object\get, index: 1, should be: object. Last edited by abidoss; 10-27-2023, 07:44 PM.
Leave a comment:
-
I added the ability to parse the whole JSON with empty path for the next hotfix release https://github.com/espocrm/espocrm/issues/2880.
You will be able to put the JSON into a variable. It will be an array. Then by using while statement, you can call record\create for every item. You will also need to use object\get, example: $id = object\get($item, 'id');
If you need to call an API endpoint to create records in a different instance, you can utilize BPM with multi-instance sub-processes (instances per each parsed item).
- Likes 2
Leave a comment:
-
Assistance regarding API results?
Hello friends, I have a JSON file with this information. When I received the file, I wanted to create leads with the information from this JSON content, but I see that it only created a single line with the first ID
json
PHP Code:
[
{
"userId": "4",
"lastname": "TEST",
"firstname": "Ahmed"
},
{
"userId": "7",
"lastname": "TEST",
"firstname": "Mehdi"
},
{
"userId": "16",
"lastname": "TEST",
"firstname": "SARA",
},
]
Tags: None
Leave a comment: