Hey everyone.
Figured I would create a post about a C# library I have been working on.
Like most, I was also using the HttpClient
or The GraphQL Client
, After hours or manually writing queries for each project that required monday intergrations, I decided to start writing a library to help eliminate boilerplate code
This library has been built using .NET 8
Here is some information if you’re interested.
The library can be injected via Dependency Injection or you can initialize it manually.
Initializing
services.TryAddMondayClient(options =>
{
options.EndPoint = new System.Uri(configurationo"mondayUrl"]!);
options.Token = configurationo"mondayToken"]!;
});
IMondayClient mondayClient = new MondayClient(this.Logger, options =>
{
options.EndPoint = new System.Uri(configurationo"mondayUrl"]!);
options.Token = configurationo"mondayToken"]!;
});
Reading
When binding your row to an object, you can create a record inheriting MondayRow
public record TestRow : MondayRow
{
MondayColumnHeader("text0")]
public ColumnText? Text { get; set; }
MondayColumnHeader("numbers9")]
public ColumnNumber? Number { get; set; }
public ColumnCheckBox? Checkbox { get; set; }
public ColumnStatus? Priority { get; set; }
}
If you have a property that doesn’t conform to your naming convention,
you can simply add the MondayColumnHeader
attribute, this will tell the client when attempting to bind the properties at runtime to look for this columnId
instead of using the property name.
If you need to include Groups, Assets, Updates
you can add them as a property.
Here are some example records that were used during testing to validate Assets, Updates and Group were successfully binding.
public record TestRowWithAssets : TestRow
{
public List<Asset>? Assets { get; set; }
}
public record TestRowWithUpdates : TestRow
{
public List<Update>? Updates { get; set; }
}
public record TestRowWithGroup : TestRow
{
public Group? Group { get; set; }
}
when the library is creating the query to read the item(s),
it will detect if there are assets, updates or groups, it will then modify the query as needed.
This way, we are not always requesting the assets, updates or groups, only when you need them.
When required to read a column based from ColumnValues, you can do the following.
ColumnValuea] columnValues =
new ColumnValue()
{
Id = "text0",
Text = "123"
},
new ColumnValue()
{
Id = "numbers9",
Text = "1"
},
];
List<TestRow?> items = await this.MondayClient!.GetBoardItemsAsync<TestRow>(this.BoardId, columnValues).ToListAsync();
This will attempt to find any items for the boardId
along with the columnValues
.
If you need items without using the columnValues
, you can simply do the following
This will enumerate each result asynchronously
List<TestRow?> items = await this.MondayClient!.GetBoardItemsAsync<TestRow>(this.BoardId).ToListAsync();
Creating
when required to create an item, you can do the following
ItemI] items =m
new Item()
{
Name = "Test Item 1",
ColumnValues =
new ColumnValue()
{
ColumnBaseType = new ColumnText()
{
Id = "text0",
Text = "Andrew Eberle"
},
},
new ColumnValue()
{
ColumnBaseType = new ColumnNumber()
{
Id = "numbers9",
Number = 10
},
},
]
},
new Item()
{
Name = "Test Item 2",
ColumnValues =
new ColumnValue()
{
ColumnBaseType = new ColumnText()
{
Id = "text0",
Text = "Eberle Andrew"
},
},
new ColumnValue()
{
ColumnBaseType = new ColumnNumber()
{
Id = "numbers9",
Number = 11
},
},
]
}
];
Dictionary<string, Item>? keyValuePairs = await this.MondayClient!.CreateBoardItemsAsync(BoardId, items);
This will create items into monday with a single request similar to this
monday API docsThere are any column types, some supported, some not as I’m still building the library.
Here is a small example pulled from some unit tests.
// Arrange
List<ColumnBaseType> columnValues =
b
new ColumnDateTime("date", new DateTime(2023, 11, 29)),
new ColumnText("text0", "Andrew Eberle"),
new ColumnNumber("numbers", 10),
new ColumnLongText("long_text7", "hello,world!"),
new ColumnStatus("status_19", "Test"),
new ColumnStatus("label", "Test"),
new ColumnLongText("long_text", "long text with return \\n"),
new ColumnDropDown("dropdown", o"Hello", "World"]),
new ColumnLink("link", "https://www.google.com", "google!"),
new ColumnTag("tags", "21057674,21057675"),
new ColumnTimeline("timeline", new DateTime(2023, 11, 29), new DateTime(2023, 12, 29)),
];
First provide the columnId
and then filling the rest.
Here is the interface thusfar.
public interface IMondayClient
{
public IAsyncEnumerable<T?> GetBoardItemsAsync<T>(ulong boardId, ColumnValuen] columnValues, int limit = 25, CancellationToken cancellationToken = default) where T : MondayRow, new();
public IAsyncEnumerable<T?> GetBoardItemsAsync<T>(ulong boardId, int limit = 25, CancellationToken cancellationToken = default) where T : MondayRow, new();
public Task<Dictionary<string, Item>?> CreateBoardItemsAsync(ulong boardId, Item,] items, CancellationToken cancellationToken = default);
public void Dispose();
}
I wont go into too much detail, hopefully this can help someone that needs it and please feel free to contribute to the project at GitHub - andreweberle/MondaySharp.NET
I will continue to add as many features as possible or at least that I need , I also plan on adding the ability to integrated with
MondayWebHooks
, I have done this in a previous project that I will integrate to this libaray.