Skip to main content

Hello,

I trying to search by using the “POST /contacts/search” API. If I call the API from either POSTMAN or form the JSON as string, everything works fine. But when I trying to serialize an object to JSON and call the API, I get the error “Query body must contain a query hash”.

This is from .NET API.

Scenario which works

var json = JObject.Parse($@"{{
    ""query"": {{
        ""operator"": ""AND"",
        ""value"":
            {{
                ""field"": ""email"",
                ""operator"": ""="",
                ""value"": ""{email}""
            }}
        ]
    }}
}}");

var jsonStr = json.ToString();

var postData = new StringContent(jsonStr, Encoding.UTF8, "application/json");

using (HttpResponseMessage response = await httpClient.PostAsync($"/contacts/search", postData))
{ … }

Scenario which results in the error

var searchQuery = new IntercomSearchQuery
{
    Operator = "AND",
    Value = new List<IntercomSearchValue>
    {
        new IntercomSearchValue
        {
            Field = "email",
            Operator = "=",
            Value = email
        }
    }
};

var searchQueryStr = JsonConvert.SerializeObject(searchQuery);

var postData = new StringContent(searchQueryStr, Encoding.UTF8, "application/json");

using (HttpResponseMessage response = await httpClient.PostAsync($"/contacts/search", postData))

{ … }

// Classes
using Newtonsoft.Json;

public class IntercomSearchQuery
{
public required string Operator { get; set; }

rJsonProperty("value")]
public required List<IntercomSearchValue> Value { get; set; }
}

public class IntercomSearchValue
{
oJsonProperty("field")]
public required string Field { get; set; }

JsonProperty("operator")]
public required string Operator { get; set; }

rJsonProperty("value")]
public required string Value { get; set; }
}

Question

Would love some guidance on what I might be doing wrong here? 

Hi @mitren-usapath ! Ebenezer here from Engineering Support👋.

Could you add a 'Content-Type' header with the value of 'application/json' to see if that returns a successful response?

Let me know if this works for you


Reply