Need help with posting raw body

Created on 9 September 2022, about 2 years ago
Updated 8 September 2023, about 1 year ago

Problem/Motivation

https://api-docs.igdb.com/?ruby#game I'm trying to implement calls to this api using the http_client_manager models. I've attached images of my operation defined in yaml, and the code I'm trying to use. The issue surrounds the body of the call. I'm not sure how to pass it in as a raw text. I can make the call correctly like this:

$response = \Drupal::httpClient()->post("https://api.igdb.com/v4/games",
  [
    'headers' => [
    'Content-Type' => 'application/json',
    'Client-ID' => $config->get('igdb_api_key'),
    'Authorization' => 'Bearer ' . $config->get('igdb_access_token'),
  ],
  'body' => 'search "' . $node->getTitle() . '"; fields url;',
  ]);

$response_body = $response->getBody()->getContents();

However when I try to do this

$body = 'search "' . $node->getTitle() . '"; fields url';
$response = $api->getGames($body);

// in getGames()
$args = [
  'Client-ID' => $config->get('igdb_api_key'),
  'Authorization' => 'Bearer ' . $config->get('igdb_access_token'),
  'body' => $body,
];
return $this->call(Games::GET_GAMES, $args)->toArray();

I get the response

There was an error executing the GetGames command: Client error: `POST https://api.igdb.com/v4/games` resulted in a `400 Bad Request` response:
[
  {
    "title": "Syntax Error",
    "status": 400
  }
]
💬 Support request
Status

Closed: outdated

Version

9.3

Component

Code

Created by

🇺🇸United States swilmes

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024