# Empty result array in Batch Read C#

**URL:** <https://community.hubspot.com/t/empty-result-array-in-batch-read-c/80236>\
**Category:** APIs & Integrations\
**Created:** [April 28, 2023, 3:38am UTC](https://community.hubspot.com/t/empty-result-array-in-batch-read-c/80236 "2023-04-28T03:38:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JHFlink](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@JHFlink](https://community.hubspot.com/u/JHFlink)\
**Post date:** [April 28, 2023, 3:38am UTC](https://community.hubspot.com/t/empty-result-array-in-batch-read-c/80236/1 "2023-04-28T03:38:35Z")

</div>

Hello,

I’m trying to do a product Batch Read to retrieve the product ID through the SKU but when I get back the request the result array is empty.

I’ve tried the code generated on the product endpoint page with our account and that seems to work so the problem might be in the formatting?

Anyhow, here’s a gist of it in C#

```lia-code-sample
JObject requestBody = new JObject
{
 {"properties", "*"},
 {"propertiesWithHistory", "*"},
 {"idProperty", "hs_sku" },
 {"inputs", new JArray
 {
 new JObject {{"id", "NBEK2_C"}},
 new JObject {{"id", "NBEK2_S"}},
 }
 }
};

RestClient.DefaultRequestHeaders["authorization"] = "Bearer " + accessToken;
RestClient.Request(new RequestHelper
{ Uri="https://api.hubapi.com/crm/v3/objects/products/batch/readarchived=false",
 Method = "POST",
 Headers = new Dictionary<string, string> { 
 { "accept", "application/json" },
 { "content-type", "application/json" },
 },

 Body = requestBody,

})

```

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [April 28, 2023, 6:59am UTC](https://community.hubspot.com/t/empty-result-array-in-batch-read-c/80236/2 "2023-04-28T06:59:02Z")

</div>

Hello @JHFlink

Based on the code you provided, it seems like you’re missing the HubSpot API key in the authorization header. You’ll need to replace `accessToken` with your actual HubSpot API key.

Additionally, you have a typo in your `Uri` parameter. The `readarchived` parameter should be appended as a query string, not as part of the path. So your `Uri` parameter should look like this:

```lia-code-sample
Uri = "https://api.hubapi.com/crm/v3/objects/products/batch/read?archived=false"

```

Finally, you might want to add error handling to your code to catch any exceptions that might be thrown during the API call. Here’s an updated version of your code with these changes

```lia-code-sample
JObject requestBody = new JObject
{
 {"properties", "*"},
 {"propertiesWithHistory", "*"},
 {"idProperty", "hs_sku" },
 {"inputs", new JArray
 {
 new JObject {{"id", "NBEK2_C"}},
 new JObject {{"id", "NBEK2_S"}},
 }
 }
};

string apiKey = "your_api_key_here";
RestClient.DefaultRequestHeaders["Authorization"] = "Bearer " + apiKey;

var response = RestClient.Request(new RequestHelper
{
 Uri = "https://api.hubapi.com/crm/v3/objects/products/batch/read?archived=false",
 Method = "POST",
 Headers = new Dictionary<string, string>
 {
 { "accept", "application/json" },
 { "content-type", "application/json" },
 },
 Body = requestBody,
});

if (response.StatusCode == HttpStatusCode.OK)
{
 var responseBody = JObject.Parse(response.Content);
 // handle the response here
}
else
{
 // handle the error here
}

```

---

<div class="post-metadata">

**Author:** ![JHFlink](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@JHFlink](https://community.hubspot.com/u/JHFlink)\
**Post date:** [April 28, 2023, 7:11am UTC](https://community.hubspot.com/t/empty-result-array-in-batch-read-c/80236/3 "2023-04-28T07:11:13Z")

</div>

Thank you for the reply!

Sorry if I was not clear enough, I do have both the token and the error/success handling, just left it out here since it was pretty trivial.

And the query string ? somehow got left out when I copied the code into here.

I kind of feel that it has something to do with the requestBody Json data, the rest api I’m using is slightly different from the one in the product endpoint examples which goes like this (and works):

```lia-code-sample
var client = new RestClient("https://api.hubapi.com/crm/v3/objects/products/batch/read?archived=false");
var request = new RestRequest(Method.POST);
request.AddHeader("accept", "application/json");
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer YOUR_ACCESS_TOKEN");
request.AddParameter("application/json", "{\"properties\":[\"seats\"],\"propertiesWithHistory\":[\"seats\"],\"idProperty\":\"hs_sku\",\"inputs\":[{\"id\":\"NBEK2_C\"},{\"id\":\"NBEK2_S\"}]}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

```

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [April 28, 2023, 7:28am UTC](https://community.hubspot.com/t/empty-result-array-in-batch-read-c/80236/4 "2023-04-28T07:28:38Z")

</div>

Use this modified version of your request body

```lia-code-sample
JObject requestBody = new JObject
{
 {"inputs", new JArray
 {
 new JObject
 {
 {"id", "NBEK2_C"},
 {"properties", new JArray{"hs_sku"}}
 },
 new JObject
 {
 {"id", "NBEK2_S"},
 {"properties", new JArray{"hs_sku"}}
 },
 }
 }
};

```

---

<div class="post-metadata">

**Author:** ![JHFlink](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@JHFlink](https://community.hubspot.com/u/JHFlink)\
**Post date:** [April 28, 2023, 11:15am UTC](https://community.hubspot.com/t/empty-result-array-in-batch-read-c/80236/5 "2023-04-28T11:15:13Z")

</div>

Thank you!

With the addition of the {“idProperty”, “hs\_sku” }, to your version of the request body it seems to work.

```lia-code-sample
JObject requestBody = new JObject
{
 {"idProperty", "hs_sku" },
 {"inputs", new JArray
 {
 new JObject
 {
 {"id", "NBEK2_C"},
 {"properties", new JArray{"hs_sku"}}
 },
 new JObject
 {
 {"id", "NBEK2_S"},
 {"properties", new JArray{"hs_sku"}}
 },
 }
 }
};

```
