A read and write example for interacting with the Contracting Works API using C#.
Contracting Works provides a GraphQL endpoint endpoint for reading data and a REST endpoint for writing data. This example demonstrates how to interact with these endpoints using C#.
Based on our firsthand experience, we recommend using NSwag to generate a C# client for the REST API and Strawberry Shake for the GraphQL API.
Open and build in visual studio or run the following in the terminal:
# Assuming you are in the root of the ReadAndWrite example folder
# Restore the graph QL tools
dotnet tool restore
# Build the example
# Should build without errors
dotnet build
Before running the example, you need to set up the necessary secrets to connect to your Contracting Works client.
- Right-click the C# project and select
Manage User Secrets
. - Add the following information:
{
"contractingWorks": {
"clientId" : "<YOUR_CLIENT_ID>",
"subjectId" : "<YOUR_USER_SUBJECT_ID>",
"apiKey" : "<YOUR_USER_API_KEY>",
}
}
# Setup the secrets
dotnet user-secrets set "contractingWorks:clientId" "<YOUR_CLIENT_ID>"
dotnet user-secrets set "contractingWorks:subjectId" "<YOUR_USER_SUBJECT_ID>"
dotnet user-secrets set "contractingWorks:apiKey" "<YOUR_USER_API_KEY>"
# List the secrets (optional)
dotnet user-secrets list
You can run the example from Visual Studio or the terminal using the following command:
dotnet run
With some luck, the sample program will perform the following:
- Successfully authenticate using Devinco Connect.
- Retrieve 10 Payment Terms and 10 Customers from Contracting Works using the GraphQL API.
- Modify the Payment Terms of the received 10 Customers through the REST API.
For further insights into refining your queries, working with Strawberry Shake and NSwag, refer to the DETAILED.md guide.