Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Trying to add elements to an array after receiving an response from an API

So basically im interacting with an online Video Poker(jacks or better) API, and i want to create an bot that automatically take decisions for me, the api requests are working fine, but i want the bot to take the decision of keep/helding the cards of the initalHand for me, following there is my code

let bodyReq = {variables:{currency:currency,amount:betAmount},query: "mutation VideoPokerBet($amount: Float!, $currency: CurrencyEnum!) {\n  videoPokerBet(amount: $amount, currency: $currency) {\n    ...CasinoBet\n    state {\n      ...CasinoGameVideoPoker\n    }\n  }\n}\n\nfragment CasinoBet on CasinoBet {\n  id\n  active\n  payoutMultiplier\n  amountMultiplier\n  amount\n  payout\n  updatedAt\n  currency\n  game\n  user {\n    id\n    name\n  }\n}\n\nfragment CasinoGameVideoPoker on CasinoGameVideoPoker {\n  playerHand {\n    suit\n    rank\n  }\n  initialHand {\n    suit\n    rank\n  }\n  handResult\n}\n"}

let bodyHeld = {variables:{identifier:identifier,held:[]},query: "mutation VideoPokerNext($held: [VideoPokerNextHeldInput!]!, $identifier: String!) {\n  videoPokerNext(held: $held, identifier: $identifier) {\n    ...CasinoBet\n    state {\n      ...CasinoGameVideoPoker\n    }\n  }\n}\n\nfragment CasinoBet on CasinoBet {\n  id\n  active\n  payoutMultiplier\n  amountMultiplier\n  amount\n  payout\n  updatedAt\n  currency\n  game\n  user {\n    id\n    name\n  }\n}\n\nfragment CasinoGameVideoPoker on CasinoGameVideoPoker {\n  playerHand {\n    suit\n    rank\n  }\n  initialHand {\n    suit\n    rank\n  }\n  handResult\n}\n"}

async function vpokerBet() {
    try{
    running.style.color = "lightgreen"
    let respData;
    while(true) {
        respData = await (await fetch(url, {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json",
                "x-access-token": apikey,
            },
            body: JSON.stringify(
                bodyReq
            )
        })).json()
        do{
        respData = await (await fetch(url, {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json",
                "x-access-token": apikey,
            },
            body: JSON.stringify(
                bodyHeld
            )
        })).json()}while(respData.data.videoPokerBet.active == true)

Basically Lets say for Example it returns an response in which the data of the InitalHand has drawn 4 K's , i want to append those cards to the held: [] Array in let bodyHeld so my next request will have keep those 4 K's, im struggling to finding out how i can do it, any help would be much appreciated ! , thanks ! :)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!