0

I am trying to use GraphQL to fetch this "Get Companies by ID" API by Harmonic AI[https://console.harmonic.ai/docs/api-reference/fetch#get-companies-by-id%5C]

I am repeatedly getting a 400 Bad Request and tested the query, but for some reason there is still a problem with my query.

This is the GraphQL query I am trying to reach, consuming HarmonicAI's API

query Query($getCompaniesByIdsIds: [Int!]!) {
  getCompaniesByIds(ids: $getCompaniesByIdsIds) {
    companyType
    contact {...}
    description
    entityUrn
    foundingDate {...}
    funding {...}
    websiteDomainAliases
    nameAliases
    fundingAttributeNullStatus
    id
    logoUrl
    legalName
    name
    ownershipStatus
    headcount
    highlights {...}
    initializedDate
    location {...}
    currentEmployees {...}
    snapshots {...}
    socials {...}
    website {...}
    tags {...}
    tractionMetrics {...}
  }
}

This is the PHP code I am using to reach the GraphQL server:

<?php

    $query = '{
        "query": "query Query($getCompaniesByIdsIds: [Int!]!) { getCompaniesByIds(ids: $getCompaniesByIdsIds) { name }}",
        "operationName": "Query",
        "variables": { "getCompaniesByIdsIds": [1, 4] }
    }';

    $yourkey = "";
    $endpoint = "https://api.harmonic.ai/graphql";


    $data = array ('query' => $query);
    $data = http_build_query($data);

    $options = array(
    'http' => array(
        'header' => 'apikey: $yourkey',
        'method'  => 'GET',
        'content' => $data
    )
    );

    $context  = stream_context_create($options);
    $result = file_get_contents($endpoint, false, $context);

    if ($result === FALSE) { /* Handle error */ }

    var_dump($result);
?>

The query seem fine but I am still getting errors.

I tried various graphql query payloads and received the same error 400 Bad Request, I believe there is a problem in how I am using graphql query but I am not sure. I tried to use their rest api and got a result so it is not a gateway problem.

j08691
  • 204,283
  • 31
  • 260
  • 272

0 Answers0