Product Insert API getting Error Bad Request

forms

#1

Hello everyone
i am new in hubsport . and i am try to call product api for insert data. But every time i call the api i am getting error like

{"status":"error","message":"Invalid input JSON on line 1, column 1: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token","correlationId":"b8c01b31-73a1-4885-8ee8-6266d49a48c4","requestId":"a60e40b17d0768d626985e20e7ef5cbd"}

and my code like

int Retval = 0;
StringBuilder SB = new StringBuilder();

        var security = SecurityInfoHubSpot.Instance;
        List<HSProduct> products = new List<HSProduct>();

        var stringPayload = JsonConvert.SerializeObject(model);
      
       
            
       

            SB.Append("[{\"name\": \"name\",\"value\": \"" + model.name + "\"},");
            SB.Append("{\"name\": \"description\",\"value\": \"" + model.description.Replace("\"", "\\\"") + "\"},");
            SB.Append("{\"name\": \"price\",\"value\": \"" + model.price + "\"},");
            SB.Append("{\"name\": \"recurringbillingfrequency\",\"value\": \"quarterly\"}");
            SB.Append("]");
      
        string baseURL = Helper.HubSpotBaseUrl + resourcePath ;
        string reqParam = String.Format("?hapikey={0}", security.HAPIKey);

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
                                   SecurityProtocolType.Tls11 |
                                   SecurityProtocolType.Tls12;
        ServicePointManager.MaxServicePointIdleTime = 1000;

        using (HttpClient client = new HttpClient())
        {

            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
         
         
            try
            {

                 var response = await client.PostAsJsonAsync(baseURL + reqParam, model);

                if (response.IsSuccessStatusCode && response.StatusCode != HttpStatusCode.NoContent)
                {
                    Retval = 1;
                }
                else
                {
                    var errtext = response.Content.ReadAsStringAsync();
                }
            }
            catch (Exception ex)
            {
                
                throw;
            }
        }

        return await Task.FromResult(Retval);

}

and my json is

[{"name": "name","value": "[Sample] 1 L Le Parfait Jar"},{"name": "description","value": "

When removes for a thorough cleaning. May be frozen - just be sure to leave enough room for expansion.

"},{"name": "price","value": "9.9500"},{"name": "recurringbillingfrequency","value": "quarterly"}]

please help me


#3

Hi @brajalal.mahanty happy to help here! Are you using this endpoint to create products in HubSpot? https://developers.hubspot.com/docs/methods/products/create-product. If so, it looks like you're using an API key rather than OAuth 2.0, is this correct?

Along with answering my questions above, can you reply to this thread with the following:

  1. The Request URL including the method and headers (Make sure Content Type is set to application/json)
  2. The raw body you're sending to HubSpot.
  3. Your HubSpot Account ID (also known as HubID or Portal ID).

#4

Now my problem is solve. Problem is in the json body