ThoughtSpot For DevelopersTFD
ThoughtSpot For Developers12mo ago
20 replies
Al

Al - Hi, I'm trying to call this API via C# cod...

Hi, I'm trying to call this API via C# code. I tested it in Postman, and it only accepts x-www-form-urlencoded, throwing an error when I use JSON. My issue is that I need to pass an array of strings, and despite serializing the ids part as a string[], I’m still getting a 500 error from the server.

Additionally, I found that the API only works with callosum/v1 included in the URL, which makes the documentation a bit unclear.

Do you have an example of how to handle this in C#?
image.png
Solution
The userId that you gave is supposed to be userid, can you check once using that? Also I gave this curl to chatgpt
curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'type=PINBOARD_ANSWER_BOOK&ids=%5B%27fded567b-8047-4185-b702-cee652725ac7%27%2C%27c88c508c-5965-4c85-9cec-236c5ef57ac5%27%5D&userid=7e9b23ce-f954-426a-986a-d1aa8be52414' 'https://{tsurl}/callosum/v1/tspublic/v1/metadata/markunmarkfavoritefor'

to code for C# this is what is produced :

using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using (HttpClient client = new HttpClient())
        {
            // Set headers
            client.DefaultRequestHeaders.Add("Accept", "application/json");

            // Prepare the form data
            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("type", "PINBOARD_ANSWER_BOOK"),
                new KeyValuePair<string, string>("ids", "['fded567b-8047-4185-b702-cee652725ac7','c88c508c-5965-4c85-9cec-236c5ef57ac5']"),
                new KeyValuePair<string, string>("userid", "7e9b23ce-f954-426a-986a-d1aa8be52414")
            });

            // Make the POST request
            HttpResponseMessage response = await client.PostAsync(
                "https://{tsurl}/callosum/v1/tspublic/v1/metadata/markunmarkfavoritefor", 
                content
            );

            // Read response
            string responseBody = await response.Content.ReadAsStringAsync();
            Console.WriteLine(responseBody);
        }
    }
}
Was this page helpful?