Workflow with Collection

Hi everyone,
I’ve been having a hard time working with workflows in backend.
So what I want to do is just create a Workflow (Phases and Cards as well) using a collection.
Workflow and Phases are being created without a problem, the problem is with Cards.
The first time code executes, it creates de workflow, and then read the phases from the collection, and then it creates the first phase, and the first card, but when it tries to create the second card, a 409 error is thrown, about a repeated ID.

I have 3 functions, the first one is to create the workflow and read the collection, then using a for loop it calls the second function, which creates the phases, and then this second function using a second for loop it calls the third function, which is to create the cards.

I already debug the code, put some console logs in each step to make sure functions are working ok, but the problem seems to be in the workflow.createCard API.

Here’s my code:
export async function arbeitsablaufEinstellen ( a , k )
{
let p ;
let arbeitsablauf ;
let ergebnis ;

arbeitsablauf  =  **await**  workflows . createWorkflow ( 
                            { 
                                "name" :  a , 
                                "description" :  "Order Workflow" 
                            } 
                        ); 
console . log ( "Workflow Created." ); 
ergebnis  =  **await**  DT . query ( "Arbeitsablauf" ) 
                    . ascending ( "phasenlage" ) 
                    . find ({ "suppressAuth" :  **true** }); 
console . log ( "DB Read." ); 
**for** ( i  =  0 ;  i  <  ergebnis.length ;  i ++) 
{ 
    p  =  **await**  phaseErstellen ( arbeitsablauf ,  k ,  ergebnis.items[i ]); 
} 
console . log ( "END" ); 
**return**  arbeitsablauf ; 

}

async function phaseErstellen ( a , k , p )
{
let krt ;
let stufe ;
let ergebnis ;

stufe  =  **await**  workflows . createPhase ( 
                    a , 
                    { 
                        "name" :  p.title 
                    }, 
                    p.phasenlage 
                ); 
console . log ( "Phase "  +  p.title  +  " Created." ); 
ergebnis  =  **await**  DT . query ( "WorkflowAufgaben" ) 
                    . eq ( "kartenphase" ,  p.phasenlage ) 
                    . ascending ( "kartenposition" ) 
                    . find ({ "suppressAuth" :  **true** }); 
console . log ( "DB Read." ); 
**for** ( j  =  0 ;  j  <  ergebnis.length ;  j ++) 
{ 
    krt  =  **await**  karteErstellen ( a ,  stufe ,  k ,  ergebnis.items[j ]); 
} 
console . log ( "Phase "  +  p.title  +  " Done." ); 
**return**  stufe ; 

}

async function karteErstellen ( a , s , k , kr )
{
let inhaber = “” ;

**if** ( kr.karteninhaber  ===  "Kundin" ) 
    inhaber  =  k ; 
**else** 
    inhaber  =  kr.karteninhaber ; 

**let**  Karte  = 
{ 
    name :  kr.title , 
    contactId :  inhaber 
}; 

**return**  **await**  workflows . createCard ( a ,  s ,  Karte ,  kr.kartenposition ) 
                . then (( kid ) => 
                { 
                    console . log ( "Card "  +  kr.title  +  " Created." ); 
                    **return**  kid ; 
                }) 
                . **catch** (( error ) => 
                { 
                    console . log ( "Card "  +  kr.title  +  " NOT Created." ); 
                    **return**  "8=D" ; 
                }); 

}