How to connect Curl to C# APIV2

I need help connecting C # to APIV2 curl to read data!

How I do?

any examples?

Thanks in advance : )

Hey @DK_89, we at monday.com don’t have any C# examples just yet, but maybe someone else here does!

I did a bit of Googling and found an example of how to make an HTTP POST request in C# here. With GraphQL, the data in your POST request dictates the API call you’re making. This is different from REST, where each endpoint corresponds to a different call or operation.

The following example shows how to structure a query that gets column values for a specific subset of line items and columns on a board.

Your headers should contain your API key, and indicate that the request body is JSON-formatted:

{
  "Authentication" : "API_KEY_HERE", 
  "Content-Type" : "application/json"
}

The actual content of the POST request should send your query and any variables in the request body like below. If you are not sending any variables, you can ignore the “variables” key-value pair.

{
  "query" : "query($rows:[Int!], $cols:[String!]){items(ids:$rows){column_values(ids:$cols){text value}}}", 
  "variables" : {"rows" :  [111,222], "cols": ["status", "number"]}
}

For mutations, your request body might look something like this (notice we’re still using the query key, despite it being a mutation).

{
  "query" : "mutation {create_webhook(board_id:148203423, event:create_item, url: \"https://myurl.ngrok.io\") { id } }"
}

Let me know if that helps!

No, I am just trying to figure out how to build the request body that gets executed.

Alrighty then :slight_smile: What are you looking to accomplish and how far have you gotten so far? Do you have a query that you’ve gotten working in the testing environment?

var client = new RestClient(“https://api.monday.com/v2/”);
var request = new RestRequest(Method.GET);
request.AddHeader(“cache-control”, “no-cache”);
request.AddHeader(“Connection”, “keep-alive”);
request.AddHeader(“Cookie”, “__cfduid=d580475ff5eb080ca4afa8689679a21e61572616637”);
request.AddHeader(“Content-Length”, “168”);
request.AddHeader(“Accept-Encoding”, “gzip, deflate”);
request.AddHeader(“Host”, “api.monday.com”);
request.AddHeader(“Cache-Control”, “no-cache”);
request.AddHeader(“Accept”, “/”);
request.AddHeader(“User-Agent”, “PostmanRuntime/7.19.0”);
request.AddHeader(“Content-Type”, “application/json”);
request.AddHeader(“Authorization”, “Bearer”)
request.AddJsonBody(“query {boards(ids: 354318007) {name}}”); ???
IRestResponse response = client.Execute(request);

The ??? piece is where I have my question, how do I format my JsonBody so that when the client executes I will get the data returned? Obviously I removed my Bearer token from the header here… :slight_smile:

Hey @kfogarty, I think I can help here!

First off, it looks like you need to change the AddJsonBody line to serialize an object into a key-value pair like so (article):

request.AddJsonBody(
    new 
    {
      query = "query {boards(ids: 354318007) {name}}",
      variables = ""
    }); // AddJsonBody serializes the object automatically

If I understand the above code correctly, once you do that and it successfully executes, you will be able to access the data returned by our server by calling methods on the response object.

Finally, you can see if any errors are thrown by our server by checking the status code or by looking at the body of the response itself. Something like response.body.errors :slight_smile: