Skip to content

Building A Query

The examples below demonstrate how to build up a query to send in a GraphQL request.

Retrieving a bet

C#
public class Program
{
    public async static Task Main()
    {
        var betId = "WinBet1"; // Your ID for the Bet

        var query = $@"
        query GetBets{{
            bets (id: ""{betId}"") {{
                nodes {{
                    id
                    toteId
                    betType {{
                        code
                    }}
                    placement {{
                        status
                        stake {{
                            decimalAmount
                            currency {{
                                code
                            }}
                        }}
                        rejectionReason
                        legs {{
                            productLegId
                            selections {{
                                productLegSelectionID
                                position
                            }}
                        }}
                    }}
                    resulting {{
                        status
                        returns {{
                            totalAmount {{
                                decimalAmount
                                currency {{
                                    code
                                }}
                            }}
                            returnAmount {{
                                decimalAmount
                                currency {{
                                    code
                                }}
                            }}
                            refundAmount {{
                                decimalAmount
                                currency {{
                                    code
                                }}
                            }}
                        }}
                    }}
                    settlement {{
                        status
                    }}
                }}
            }}
        }}";
    }
}
Go
package main

import (
  "fmt"
)

func main() {
  betId := "WinBet1" // Your ID for the Bet

  query := fmt.Sprintf(`
    query GetBets {
      bets(id: "%s") {
        nodes {
          id
          toteId
          betType {
            code
          }
          placement {
            status
            stake {
              decimalAmount
              currency {
                code
              }
            }
            rejectionReason
            legs {
              productLegId
              selections {
                productLegSelectionID
                position
              }
            }
          }
          resulting {
            status
            returns {
              totalAmount {
                decimalAmount
                currency {
                  code
                }
              }
              returnAmount {
                decimalAmount
                currency {
                  code
                }
              }
              refundAmount {
                decimalAmount
                currency {
                  code
                }
              }
            }
          }
          settlement {
            status
          }
        }
      }
    }`, betId)
}
Node js
"use strict";

const betId = "WinBet1"; // Your ID for the Bet

const query = `
      query GetBets {
          bets(id: "${betId}") {
              nodes {
                  id
                  toteId
                  betType {
                      code
                  }
                  placement {
                      status
                      stake {
                          decimalAmount
                          currency {
                              code
                          }
                      }
                      rejectionReason
                      legs {
                          productLegId
                          selections {
                              productLegSelectionID
                              position
                          }
                      }
                  }
                  resulting {
                      status
                      returns {
                          totalAmount {
                              decimalAmount
                              currency {
                                  code
                              }
                          }
                          returnAmount {
                              decimalAmount
                              currency {
                                  code
                              }
                          }
                          refundAmount {
                              decimalAmount
                              currency {
                                  code
                              }
                          }
                      }
                  }
                  settlement {
                      status
                  }
              }
          }
      }`;
Java
package org.example;

import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        var betId = "WinBet1"; // Your ID for the Bet

        var query = String.format("""
                  query GetBets {
                  bets(id: "%s") {
                    nodes {
                      id
                      toteId
                      betType {
                        code
                      }
                      placement {
                        status
                        stake {
                          decimalAmount
                          currency {
                            code
                          }
                        }
                        rejectionReason
                        legs {
                          productLegId
                          selections {
                            productLegSelectionID
                            position
                          }
                        }
                      }
                      resulting {
                        status
                        returns {
                          totalAmount {
                            decimalAmount
                            currency {
                              code
                            }
                          }
                          returnAmount {
                            decimalAmount
                            currency {
                              code
                            }
                          }
                          refundAmount {
                            decimalAmount
                            currency {
                              code
                            }
                          }
                        }
                      }
                      settlement {
                        status
                      }
                    }
                  }
                }""", betId);
    }
}
Python
import asyncio

async def main():
    bet_id = "WinBet1"  # Your ID for the Bet

    query = f"""
    query GetBets {{
        bets (id: "{bet_id}") {{
            nodes {{
                id
                toteId
                betType {{
                    code
                }}
                placement {{
                    status
                    stake {{
                        decimalAmount
                        currency {{
                            code
                        }}
                    }}
                    rejectionReason
                    legs {{
                        productLegId
                        selections {{
                            productLegSelectionID
                            position
                        }}
                    }}
                }}
                resulting {{
                    status
                    returns {{
                        totalAmount {{
                            decimalAmount
                            currency {{
                                code
                            }}
                        }}
                        returnAmount {{
                            decimalAmount
                            currency {{
                                code
                            }}
                        }}
                        refundAmount {{
                            decimalAmount
                            currency {{
                                code
                            }}
                        }}
                    }}
                }}
                settlement {{
                    status
                }}
            }}
        }}
    }}"""

asyncio.run(main())

Placing multiple bets

C#
public class Program
{
    public async static Task Main()
    {
        var ticketId = "Ticket1"; // Your ID for the Ticket

        var bets = new List<PlaceBetInput> {
            new() {
                BetId = "WinBet1", // Your ID for the Bet
                Amount = 1.00m,
                CurrencyCode = "GBP",
                ProductId = "", // Retrieved from the Partner Product API
                Legs = new List<PlaceBetLegInput> {
                    new() {
                        ProductLegId = "", // Retrieved from the Partner Product API
                        Selections = new List<PlaceBetSelectionInput> {
                            new() {
                                ProductLegSelectionId = "" // Retrieved from the Partner Product API
                            }
                        }
                    }
                }
            },
            new() {
                BetId = "ExactaBet2", // Your ID for the Bet
                Amount = 2.00m,
                CurrencyCode = "GBP",
                ProductId = "", // Retrieved from the Partner Product API
                Legs = new List<PlaceBetLegInput> {
                    new() {
                        ProductLegId = "", // Retrieved from the Partner Product API
                        Selections = new List<PlaceBetSelectionInput> {
                            new() {
                                ProductLegSelectionId = "", // Retrieved from the Partner Product API
                                Position = 1
                            },
                            new() {
                                ProductLegSelectionId = "", // Retrieved from the Partner Product API
                                Position = 2
                            }
                        }
                    }
                }
            }
        };

        var query = $@"
    mutation PlaceBet {{
        placeBets(
            input: 
            {{
                ticketId: ""{ticketId}""
                bets: [
                    {string.Concat(bets.Select(BuildBet))}
                ]
            }}
        ) {{
            ticket {{
                id
                toteId
                bets {{
                    nodes {{
                        id
                        toteId
                        betType {{
                            code
                        }}
                        placement {{
                            status
                            stake {{
                                decimalAmount
                                currency {{
                                    code
                                }}
                            }}
                            rejectionReason
                            legs {{
                                productLegId
                                selections {{
                                    productLegSelectionID
                                    position
                                }}
                            }}
                        }}
                    }}
                }}
            }}
        }}
    }}";
    }

    private static string BuildBet(PlaceBetInput bet)
    {
        var legs = string.Concat(bet.Legs.Select(BuildLeg));
        return $@"{{ betId: ""{bet.BetId}"", productId: ""{bet.ProductId}"", stake: {{ currencyCode: {bet.CurrencyCode}, totalAmount: {bet.Amount} }}, legs: [{legs}] }}";
    }

    private static string BuildLeg(PlaceBetLegInput leg)
    {
        var selections = string.Concat(leg.Selections.Select(BuildSelection));
        return $"{{ productLegId: \"{leg.ProductLegId}\", selections: [{selections}] }}";
    }

    private static string BuildSelection(PlaceBetSelectionInput selection)
    {
        return $"{{ productLegSelectionID: \"{0}\" }}";
    }
}

public class PlaceBetInput
{
    public string BetId { get; set; }

    public string CurrencyCode { get; set; }

    public decimal Amount { get; set; }

    public string ProductId { get; set; }

    public List<PlaceBetLegInput> Legs { get; set; }
}

public class PlaceBetLegInput
{
    public string ProductLegId { get; set; }

    public List<PlaceBetSelectionInput> Selections { get; set; }
}

public class PlaceBetSelectionInput
{
    public string ProductLegSelectionId { get; set; }

    public int Position { get; set; }
}
Go
package main

import (
  "fmt"
  "strings"
)

func main() {
  ticketId := "Ticket1" // Your ID for the Ticket

  bets := []PlaceBetInput{
    {
      BetId:        "WinBet1", // Your ID for the Bet
      Amount:       1.00,
      CurrencyCode: "GBP",
      ProductId:    "", // Retrieved from the Partner Product API
      Legs: []PlaceBetLegInput{
        {
          ProductLegId: "", // Retrieved from the Partner Product API
          Selections: []PlaceBetSelectionInput{
            {
              ProductLegSelectionId: "", // Retrieved from the Partner Product API
              Position:              1,
            },
          },
        },
      },
    },
    {
      BetId:        "ExactaBet2", // Your ID for the Bet
      Amount:       2.00,
      CurrencyCode: "GBP",
      ProductId:    "", // Retrieved from the Partner Product API
      Legs: []PlaceBetLegInput{
        {
          ProductLegId: "", // Retrieved from the Partner Product API
          Selections: []PlaceBetSelectionInput{
            {
              ProductLegSelectionId: "", // Retrieved from the Partner Product API
              Position:              1,
            },
            {
              ProductLegSelectionId: "", // Retrieved from the Partner Product API
              Position:              2,
            },
          },
        },
      },
    },
  }

  var betsStr strings.Builder
  for _, bet := range bets {
    betsStr.WriteString(buildBet(bet))
  }

  query := fmt.Sprintf(`
    mutation PlaceBet {
      placeBets(
        input: {
          ticketId: "%s"
          bets: [
            %s
          ]
        }
      ) {
        ticket {
          id
          toteId
          bets {
            nodes {
              id
              toteId
              betType {
                code
              }
              placement {
                status
                stake {
                  decimalAmount
                  currency {
                    code
                  }
                }
                rejectionReason
                legs {
                  productLegId
                  selections {
                    productLegSelectionID
                    position
                  }
                }
              }
            }
          }
        }
      }
    }`, ticketId, betsStr)
}

func buildBet(bet PlaceBetInput) string {
  return fmt.Sprintf(`{
    betId: "%s",
    productId: "%s",
    stake: {
      currencyCode: %s,
      totalAmount: %s
    },
    legs: [%s]
  }`, bet.BetId, bet.ProductId, bet.CurrencyCode, bet.Amount, buildLegs(bet.Legs))
}

func buildLegs(legs []PlaceBetLegInput) string {
  var builder strings.Builder

  for _, leg := range legs {
    selectionStrings := buildSelections(leg.Selections)
    fmt.Fprintf(&builder, `{ productLegId: "%s", selections: [%s] }`, leg.ProductLegId, selectionStrings)
  }

  return builder.String()
}

func buildSelections(selections []PlaceBetSelectionInput) string {
  var builder strings.Builder

  for _, selection := range selections {
    fmt.Fprintf(&builder, `{ productLegSelectionID: "%s", position: %d }`, selection.ProductLegSelectionId, selection.Position)
  }

  return builder.String()
}

type PlaceBetInput struct {
  BetId        string             `json:"betId"`
  CurrencyCode string             `json:"currencyCode"`
  Amount       float32            `json:"amount"`
  ProductId    string             `json:"productId"`
  Legs         []PlaceBetLegInput `json:"legs"`
}

type PlaceBetLegInput struct {
  ProductLegId string                   `json:"productLegId"`
  Selections   []PlaceBetSelectionInput `json:"selections"`
}

type PlaceBetSelectionInput struct {
  ProductLegSelectionId string `json:"productLegSelectionID"`
  Position              int    `json:"position"`
}
Node js
"use strict";

const ticketId = "Ticket1"; // Your ID for the Ticket

const bets = [
    {
        betId: "WinBet1", // Your ID for the Bet
        amount: 1.00,
        currencyCode: "GBP",
        productId: "", // Retrieved from the Partner Product API
        legs: [
            {
                productLegId: "", // Retrieved from the Partner Product API
                selections: [
                    {
                        productLegSelectionId: "" // Retrieved from the Partner Product API
                    }
                ]
            }
        ]
    },
    {
        betId: "ExactaBet2", // Your ID for the Bet
        amount: 2.00,
        currencyCode: "GBP",
        productId: "", // Retrieved from the Partner Product API
        legs: [
            {
                productLegId: "", // Retrieved from the Partner Product API
                selections: [
                    {
                        productLegSelectionId: "" // Retrieved from the Partner Product API
                    }
                ]
            }
        ]
    }
];

const query = `
    mutation PlaceBet {
        placeBets(
            input: {
                ticketId: "${ticketId}",
                bets: [
                    ${bets.map(buildBet).join("")}
                ]
            }
        ) {
            ticket {
                id
                toteId
                bets {
                    nodes {
                        id
                        toteId
                        betType {
                            code
                        }
                        placement {
                            status
                            stake {
                                decimalAmount
                                currency {
                                    code
                                }
                            }
                            rejectionReason
                            legs {
                                productLegId
                                selections {
                                    productLegSelectionID
                                    position
                                }
                            }
                        }
                    }
                }
            }
        }
    }`;

const buildBet = (bet) => {
    const legs = bet.legs.map(buildLeg).join("");
    return `
        {
            betId: "${bet.betId}",
            productId: "${bet.productId}",
            stake: {
                currencyCode: ${bet.currencyCode},
                totalAmount: ${bet.amount}
            },
            legs: [${legs}]
        }`;
};

const buildLeg = (leg) => {
    const selections = leg.selections.map(buildSelection).join("");
    return `{ productLegId: "${leg.productLegId}", selections: [ ${selections} ] }`;
};

const buildSelection = (selection) => {
    return `{ productLegSelectionID: "${selection.productLegSelectionId}" }`;
};
Java
package org.example;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        var ticketId = "Ticket1"; // Your ID for the Ticket

        List<PlaceBetInput> bets = new ArrayList<>();

        var winBet = new PlaceBetInput();
        winBet.setBetId("WinBet1"); // Your ID for the Bet
        winBet.setAmount(1.00);
        winBet.setCurrencyCode("GBP");
        winBet.setProductId(""); // Retrieved from the Partner Product API

        List<PlaceBetLegInput> winBetLegs = new ArrayList<>();
        var winBetLeg = new PlaceBetLegInput();
        winBetLeg.setProductLegId(""); // Retrieved from the Partner Product API

        List<PlaceBetSelectionInput> winBetSelections = new ArrayList<>();
        var winBetSelection = new PlaceBetSelectionInput();
        winBetSelection.setProductLegSelectionId(""); // Retrieved from the Partner Product API
        winBetSelections.add(winBetSelection);

        winBetLeg.setSelections(winBetSelections);
        winBetLegs.add(winBetLeg);

        winBet.setLegs(winBetLegs);
        bets.add(winBet);

        var exactaBet = new PlaceBetInput();
        exactaBet.setBetId("ExactaBet2"); // Your ID for the Bet
        exactaBet.setAmount(2.00);
        exactaBet.setCurrencyCode("GBP");
        exactaBet.setProductId(""); // Retrieved from the Partner Product API

        List<PlaceBetLegInput> exactaBetLegs = new ArrayList<>();
        var exactaBetLeg = new PlaceBetLegInput();
        exactaBetLeg.setProductLegId(""); // Retrieved from the Partner Product API

        List<PlaceBetSelectionInput> exactaBetSelections = new ArrayList<>();
        var exactaBetSelection = new PlaceBetSelectionInput();
        exactaBetSelection.setProductLegSelectionId(""); // Retrieved from the Partner Product API
        exactaBetSelections.add(exactaBetSelection);

        exactaBetLeg.setSelections(exactaBetSelections);
        exactaBetLegs.add(exactaBetLeg);

        exactaBet.setLegs(exactaBetLegs);
        bets.add(exactaBet);

        var betsStr = bets.stream()
                .map(Main::buildBet)
                .collect(Collectors.joining(""));

        var query = String.format("""
                    mutation PlaceBet {
                    placeBets(
                        input: {
                            ticketId: "%s"
                            bets: [%s]
                        }
                    ) {
                        ticket {
                            id
                            toteId
                            bets {
                                nodes {
                                    id
                                    toteId
                                    betType {
                                        code
                                    }
                                    placement {
                                        status
                                        stake {
                                            decimalAmount
                                            currency {
                                                code
                                            }
                                        }
                                        rejectionReason
                                        legs {
                                            productLegId
                                            selections {
                                                productLegSelectionID
                                                position
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }""", ticketId, betsStr);
    }

    private static String buildBet(PlaceBetInput bet) {
        var legs = bet.getLegs().stream()
                .map(Main::buildLeg)
                .collect(Collectors.joining(", "));

        return String.format("{ betId: \"%s\", productId: \"%s\", stake: { currencyCode: %s, totalAmount: %s }, legs: [%s] }",
                bet.getBetId(), bet.getProductId(), bet.getCurrencyCode(), bet.getAmount(), legs);
    }

    private static String buildLeg(PlaceBetLegInput leg) {
        var selections = leg.getSelections().stream()
                .map(Main::buildSelection)
                .collect(Collectors.joining(", "));

        return String.format("{ productLegId: \"%s\", selections: [%s] }",
                leg.getProductLegId(), selections);
    }

    private static String buildSelection(PlaceBetSelectionInput selection) {
        return String.format("{ productLegSelectionID: \"%s\", position: %d }",
                selection.getProductLegSelectionId(), selection.getPosition());
    }
}
Python
import asyncio

class PlaceBetSelectionInput:
    def __init__(self, productLegSelectionID, position=None):
        self.productLegSelectionID = productLegSelectionID
        self.position = position

class PlaceBetLegInput:
    def __init__(self, productLegId, selections):
        self.productLegId = productLegId
        self.selections = selections

class PlaceBetInput:
    def __init__(self, betId, amount, currencyCode, productId, legs):
        self.betId = betId
        self.amount = amount
        self.currencyCode = currencyCode
        self.productId = productId
        self.legs = legs

def buildPlaceBetQuery(ticketId: str, bets: list[PlaceBetInput]) -> str:
  def buildBet(bet: PlaceBetInput) -> str:
    legs = ''.join([buildLeg(leg) for leg in bet.legs])
    return f'{{ betId: "{bet.betId}", productId: "{bet.productId}", ' \
        f'stake: {{ currencyCode: {bet.currencyCode}, totalAmount: {bet.amount} }}, ' \
        f'legs: [{legs}] }}'

  def buildLeg(leg: PlaceBetLegInput) -> str:
    selections = ''.join([buildSelection(selection) for selection in leg.selections])
    return f'{{ productLegId: "{leg.productLegId}", selections: [{selections}] }}'

  def buildSelection(selection: PlaceBetSelectionInput) -> str:
    return f'{{ productLegSelectionID: "{selection.productLegSelectionID}" }}'

  betsStr = ', '.join([buildBet(bet) for bet in bets])
  return f'''
  mutation PlaceBet {{
    placeBets(
      input: {{
        ticketId: "{ticketId}"
        bets: [
          {betsStr}
        ]
      }}
    ) {{
      ticket {{
        id
        toteId
        bets {{
          nodes {{
            id
            toteId
            betType {{
              code
            }}
            placement {{
              status
              stake {{
                decimalAmount
                currency {{
                  code
                }}
              }}
              rejectionReason
              legs {{
                productLegId
                selections {{
                  productLegSelectionID
                  position
                }}
              }}
            }}
          }}
        }}
      }}
    }}
  }}
  '''

async def main():
    ticket_id = "Ticket1"  # Your ID for the Ticket

    bets = [
        PlaceBetInput(
            betId="WinBet1",  # Your ID for the Bet
            amount=1.00,
            currencyCode="GBP",
            productId="",  # Retrieved from the Partner Product API
            legs=[
                PlaceBetLegInput(
                    productLegId="",  # Retrieved from the Partner Product API
                    selections=[
                        PlaceBetSelectionInput(
                            productLegSelectionID=""  # Retrieved from the Partner Product API
                        )
                    ]
                )
            ]
        ),
        PlaceBetInput(
            betId="ExactaBet2",  # Your ID for the Bet
            amount=2.00,
            currencyCode="GBP",
            productId="",  # Retrieved from the Partner Product API
            legs=[
                PlaceBetLegInput(
                    productLegId="",  # Retrieved from the Partner Product API
                    selections=[
                        PlaceBetSelectionInput(
                            productLegSelectionID="",  # Retrieved from the Partner Product API
                            position=1
                        ),
                        PlaceBetSelectionInput(
                            productLegSelectionID="",  # Retrieved from the Partner Product API
                            position=2
                        )
                    ]
                )
            ]
        )
    ]

    query = buildPlaceBetQuery(ticket_id, bets)

# Run the async main function
asyncio.run(main())

Placing multiple async bets

C#
public class Program
{
    public async static Task Main()
    {
        var ticketId = "Ticket1"; // Your ID for the Ticket

        var bets = new List<PlaceBetInput> {
            new() {
                BetId = "WinBet1", // Your ID for the Bet
                Amount = 1.00m,
                CurrencyCode = "GBP",
                ProductId = "", // Retrieved from the Partner Product API
                Legs = new List<PlaceBetLegInput> {
                    new() {
                        ProductLegId = "", // Retrieved from the Partner Product API
                        Selections = new List<PlaceBetSelectionInput> {
                            new() {
                                ProductLegSelectionId = "" // Retrieved from the Partner Product API
                            }
                        }
                    }
                }
            },
            new() {
                BetId = "ExactaBet2", // Your ID for the Bet
                Amount = 2.00m,
                CurrencyCode = "GBP",
                ProductId = "", // Retrieved from the Partner Product API
                Legs = new List<PlaceBetLegInput> {
                    new() {
                        ProductLegId = "", // Retrieved from the Partner Product API
                        Selections = new List<PlaceBetSelectionInput> {
                            new() {
                                ProductLegSelectionId = "", // Retrieved from the Partner Product API
                                Position = 1
                            },
                            new() {
                                ProductLegSelectionId = "", // Retrieved from the Partner Product API
                                Position = 2
                            }
                        }
                    }
                }
            }
        };

        var query = $@"
    mutation PlaceBet {{
        placeBetsAsync(
            input: 
            {{
                ticketId: ""{ticketId}""
                bets: [
                    {string.Concat(bets.Select(BuildBet))}
                ]
            }}
        ) {{
            ticket {{
                id
                toteId
                bets {{
                    nodes {{
                        id
                        toteId
                        betType {{
                            code
                        }}
                        placement {{
                            status
                            stake {{
                                decimalAmount
                                currency {{
                                    code
                                }}
                            }}
                            rejectionReason
                            legs {{
                                productLegId
                                selections {{
                                    productLegSelectionID
                                    position
                                }}
                            }}
                        }}
                    }}
                }}
            }}
        }}
    }}";
    }

    private static string BuildBet(PlaceBetInput bet)
    {
        var legs = string.Concat(bet.Legs.Select(BuildLeg));
        return $@"{{ betId: ""{bet.BetId}"", productId: ""{bet.ProductId}"", stake: {{ currencyCode: {bet.CurrencyCode}, totalAmount: {bet.Amount} }}, legs: [{legs}] }}";
    }

    private static string BuildLeg(PlaceBetLegInput leg)
    {
        var selections = string.Concat(leg.Selections.Select(BuildSelection));
        return $"{{ productLegId: \"{leg.ProductLegId}\", selections: [{selections}] }}";
    }

    private static string BuildSelection(PlaceBetSelectionInput selection)
    {
        return $"{{ productLegSelectionID: \"{0}\" }}";
    }
}

public class PlaceBetInput
{
    public string BetId { get; set; }

    public string CurrencyCode { get; set; }

    public decimal Amount { get; set; }

    public string ProductId { get; set; }

    public List<PlaceBetLegInput> Legs { get; set; }
}

public class PlaceBetLegInput
{
    public string ProductLegId { get; set; }

    public List<PlaceBetSelectionInput> Selections { get; set; }
}

public class PlaceBetSelectionInput
{
    public string ProductLegSelectionId { get; set; }

    public int Position { get; set; }
}
Go
package main

import (
  "fmt"
  "strings"
)

func main() {
  ticketId := "Ticket1" // Your ID for the Ticket

  bets := []PlaceBetInput{
    {
      BetId:        "WinBet1", // Your ID for the Bet
      Amount:       1.00,
      CurrencyCode: "GBP",
      ProductId:    "", // Retrieved from the Partner Product API
      Legs: []PlaceBetLegInput{
        {
          ProductLegId: "", // Retrieved from the Partner Product API
          Selections: []PlaceBetSelectionInput{
            {
              ProductLegSelectionId: "", // Retrieved from the Partner Product API
              Position:              1,
            },
          },
        },
      },
    },
    {
      BetId:        "ExactaBet2", // Your ID for the Bet
      Amount:       2.00,
      CurrencyCode: "GBP",
      ProductId:    "", // Retrieved from the Partner Product API
      Legs: []PlaceBetLegInput{
        {
          ProductLegId: "", // Retrieved from the Partner Product API
          Selections: []PlaceBetSelectionInput{
            {
              ProductLegSelectionId: "", // Retrieved from the Partner Product API
              Position:              1,
            },
            {
              ProductLegSelectionId: "", // Retrieved from the Partner Product API
              Position:              2,
            },
          },
        },
      },
    },
  }

  var betsStr strings.Builder
  for _, bet := range bets {
    betsStr.WriteString(buildBet(bet))
  }

  query := fmt.Sprintf(`
    mutation PlaceBet {
      placeBetsAsync(
        input: {
          ticketId: "%s"
          bets: [
            %s
          ]
        }
      ) {
        ticket {
          id
          toteId
          bets {
            nodes {
              id
              toteId
              betType {
                code
              }
              placement {
                status
                stake {
                  decimalAmount
                  currency {
                    code
                  }
                }
                rejectionReason
                legs {
                  productLegId
                  selections {
                    productLegSelectionID
                    position
                  }
                }
              }
            }
          }
        }
      }
    }`, ticketId, betsStr)
}

func buildBet(bet PlaceBetInput) string {
  return fmt.Sprintf(`{
    betId: "%s",
    productId: "%s",
    stake: {
      currencyCode: %s,
      totalAmount: %s
    },
    legs: [%s]
  }`, bet.BetId, bet.ProductId, bet.CurrencyCode, bet.Amount, buildLegs(bet.Legs))
}

func buildLegs(legs []PlaceBetLegInput) string {
  var builder strings.Builder

  for _, leg := range legs {
    selectionStrings := buildSelections(leg.Selections)
    fmt.Fprintf(&builder, `{ productLegId: "%s", selections: [%s] }`, leg.ProductLegId, selectionStrings)
  }

  return builder.String()
}

func buildSelections(selections []PlaceBetSelectionInput) string {
  var builder strings.Builder

  for _, selection := range selections {
    fmt.Fprintf(&builder, `{ productLegSelectionID: "%s", position: %d }`, selection.ProductLegSelectionId, selection.Position)
  }

  return builder.String()
}

type PlaceBetInput struct {
  BetId        string             `json:"betId"`
  CurrencyCode string             `json:"currencyCode"`
  Amount       float32            `json:"amount"`
  ProductId    string             `json:"productId"`
  Legs         []PlaceBetLegInput `json:"legs"`
}

type PlaceBetLegInput struct {
  ProductLegId string                   `json:"productLegId"`
  Selections   []PlaceBetSelectionInput `json:"selections"`
}

type PlaceBetSelectionInput struct {
  ProductLegSelectionId string `json:"productLegSelectionID"`
  Position              int    `json:"position"`
}
Node js
"use strict";

const ticketId = "Ticket1"; // Your ID for the Ticket

const bets = [
    {
        betId: "WinBet1", // Your ID for the Bet
        amount: 1.00,
        currencyCode: "GBP",
        productId: "", // Retrieved from the Partner Product API
        legs: [
            {
                productLegId: "", // Retrieved from the Partner Product API
                selections: [
                    {
                        productLegSelectionId: "" // Retrieved from the Partner Product API
                    }
                ]
            }
        ]
    },
    {
        betId: "ExactaBet2", // Your ID for the Bet
        amount: 2.00,
        currencyCode: "GBP",
        productId: "", // Retrieved from the Partner Product API
        legs: [
            {
                productLegId: "", // Retrieved from the Partner Product API
                selections: [
                    {
                        productLegSelectionId: "" // Retrieved from the Partner Product API
                    }
                ]
            }
        ]
    }
];

const query = `
    mutation PlaceBet {
        placeBetsAsync(
            input: {
                ticketId: "${ticketId}",
                bets: [
                    ${bets.map(buildBet).join("")}
                ]
            }
        ) {
            ticket {
                id
                toteId
                bets {
                    nodes {
                        id
                        toteId
                        betType {
                            code
                        }
                        placement {
                            status
                            stake {
                                decimalAmount
                                currency {
                                    code
                                }
                            }
                            rejectionReason
                            legs {
                                productLegId
                                selections {
                                    productLegSelectionID
                                    position
                                }
                            }
                        }
                    }
                }
            }
        }
    }`;

const buildBet = (bet) => {
    const legs = bet.legs.map(buildLeg).join("");
    return `
        {
            betId: "${bet.betId}",
            productId: "${bet.productId}",
            stake: {
                currencyCode: ${bet.currencyCode},
                totalAmount: ${bet.amount}
            },
            legs: [${legs}]
        }`;
};

const buildLeg = (leg) => {
    const selections = leg.selections.map(buildSelection).join("");
    return `{ productLegId: "${leg.productLegId}", selections: [ ${selections} ] }`;
};

const buildSelection = (selection) => {
    return `{ productLegSelectionID: "${selection.productLegSelectionId}" }`;
};
Java
package org.example;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        var ticketId = "Ticket1"; // Your ID for the Ticket

        List<PlaceBetInput> bets = new ArrayList<>();

        var winBet = new PlaceBetInput();
        winBet.setBetId("WinBet1"); // Your ID for the Bet
        winBet.setAmount(1.00);
        winBet.setCurrencyCode("GBP");
        winBet.setProductId(""); // Retrieved from the Partner Product API

        List<PlaceBetLegInput> winBetLegs = new ArrayList<>();
        var winBetLeg = new PlaceBetLegInput();
        winBetLeg.setProductLegId(""); // Retrieved from the Partner Product API

        List<PlaceBetSelectionInput> winBetSelections = new ArrayList<>();
        var winBetSelection = new PlaceBetSelectionInput();
        winBetSelection.setProductLegSelectionId(""); // Retrieved from the Partner Product API
        winBetSelections.add(winBetSelection);

        winBetLeg.setSelections(winBetSelections);
        winBetLegs.add(winBetLeg);

        winBet.setLegs(winBetLegs);
        bets.add(winBet);

        var exactaBet = new PlaceBetInput();
        exactaBet.setBetId("ExactaBet2"); // Your ID for the Bet
        exactaBet.setAmount(2.00);
        exactaBet.setCurrencyCode("GBP");
        exactaBet.setProductId(""); // Retrieved from the Partner Product API

        List<PlaceBetLegInput> exactaBetLegs = new ArrayList<>();
        var exactaBetLeg = new PlaceBetLegInput();
        exactaBetLeg.setProductLegId(""); // Retrieved from the Partner Product API

        List<PlaceBetSelectionInput> exactaBetSelections = new ArrayList<>();
        var exactaBetSelection = new PlaceBetSelectionInput();
        exactaBetSelection.setProductLegSelectionId(""); // Retrieved from the Partner Product API
        exactaBetSelections.add(exactaBetSelection);

        exactaBetLeg.setSelections(exactaBetSelections);
        exactaBetLegs.add(exactaBetLeg);

        exactaBet.setLegs(exactaBetLegs);
        bets.add(exactaBet);

        var betsStr = bets.stream()
                .map(Main::buildBet)
                .collect(Collectors.joining(""));

        var query = String.format("""
                    mutation PlaceBet {
                    placeBetsAsync(
                        input: {
                            ticketId: "%s"
                            bets: [%s]
                        }
                    ) {
                        ticket {
                            id
                            toteId
                            bets {
                                nodes {
                                    id
                                    toteId
                                    betType {
                                        code
                                    }
                                    placement {
                                        status
                                        stake {
                                            decimalAmount
                                            currency {
                                                code
                                            }
                                        }
                                        rejectionReason
                                        legs {
                                            productLegId
                                            selections {
                                                productLegSelectionID
                                                position
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }""", ticketId, betsStr);
    }

    private static String buildBet(PlaceBetInput bet) {
        var legs = bet.getLegs().stream()
                .map(Main::buildLeg)
                .collect(Collectors.joining(", "));

        return String.format("{ betId: \"%s\", productId: \"%s\", stake: { currencyCode: %s, totalAmount: %s }, legs: [%s] }",
                bet.getBetId(), bet.getProductId(), bet.getCurrencyCode(), bet.getAmount(), legs);
    }

    private static String buildLeg(PlaceBetLegInput leg) {
        var selections = leg.getSelections().stream()
                .map(Main::buildSelection)
                .collect(Collectors.joining(", "));

        return String.format("{ productLegId: \"%s\", selections: [%s] }",
                leg.getProductLegId(), selections);
    }

    private static String buildSelection(PlaceBetSelectionInput selection) {
        return String.format("{ productLegSelectionID: \"%s\", position: %d }",
                selection.getProductLegSelectionId(), selection.getPosition());
    }
}
Python
import asyncio

class PlaceBetSelectionInput:
    def __init__(self, productLegSelectionID, position=None):
        self.productLegSelectionID = productLegSelectionID
        self.position = position

class PlaceBetLegInput:
    def __init__(self, productLegId, selections):
        self.productLegId = productLegId
        self.selections = selections

class PlaceBetInput:
    def __init__(self, betId, amount, currencyCode, productId, legs):
        self.betId = betId
        self.amount = amount
        self.currencyCode = currencyCode
        self.productId = productId
        self.legs = legs

def buildPlaceBetQuery(ticketId: str, bets: list[PlaceBetInput]) -> str:
  def buildBet(bet: PlaceBetInput) -> str:
    legs = ''.join([buildLeg(leg) for leg in bet.legs])
    return f'{{ betId: "{bet.betId}", productId: "{bet.productId}", ' \
        f'stake: {{ currencyCode: {bet.currencyCode}, totalAmount: {bet.amount} }}, ' \
        f'legs: [{legs}] }}'

  def buildLeg(leg: PlaceBetLegInput) -> str:
    selections = ''.join([buildSelection(selection) for selection in leg.selections])
    return f'{{ productLegId: "{leg.productLegId}", selections: [{selections}] }}'

  def buildSelection(selection: PlaceBetSelectionInput) -> str:
    return f'{{ productLegSelectionID: "{selection.productLegSelectionID}" }}'

  betsStr = ', '.join([buildBet(bet) for bet in bets])
  return f'''
  mutation PlaceBet {{
    placeBetsAsync(
      input: {{
        ticketId: "{ticketId}"
        bets: [
          {betsStr}
        ]
      }}
    ) {{
      ticket {{
        id
        toteId
        bets {{
          nodes {{
            id
            toteId
            betType {{
              code
            }}
            placement {{
              status
              stake {{
                decimalAmount
                currency {{
                  code
                }}
              }}
              rejectionReason
              legs {{
                productLegId
                selections {{
                  productLegSelectionID
                  position
                }}
              }}
            }}
          }}
        }}
      }}
    }}
  }}
  '''

async def main():
    ticket_id = "Ticket1"  # Your ID for the Ticket

    bets = [
        PlaceBetInput(
            betId="WinBet1",  # Your ID for the Bet
            amount=1.00,
            currencyCode="GBP",
            productId="",  # Retrieved from the Partner Product API
            legs=[
                PlaceBetLegInput(
                    productLegId="",  # Retrieved from the Partner Product API
                    selections=[
                        PlaceBetSelectionInput(
                            productLegSelectionID=""  # Retrieved from the Partner Product API
                        )
                    ]
                )
            ]
        ),
        PlaceBetInput(
            betId="ExactaBet2",  # Your ID for the Bet
            amount=2.00,
            currencyCode="GBP",
            productId="",  # Retrieved from the Partner Product API
            legs=[
                PlaceBetLegInput(
                    productLegId="",  # Retrieved from the Partner Product API
                    selections=[
                        PlaceBetSelectionInput(
                            productLegSelectionID="",  # Retrieved from the Partner Product API
                            position=1
                        ),
                        PlaceBetSelectionInput(
                            productLegSelectionID="",  # Retrieved from the Partner Product API
                            position=2
                        )
                    ]
                )
            ]
        )
    ]

    query = buildPlaceBetQuery(ticket_id, bets)

# Run the async main function
asyncio.run(main())