Using RestSharp to make an API insert call |
12/2/2023 7:38:43 AM |
ASPRunner.NET General questions | |
D
david powell author
Hi, C# code (using RestCharp): var client = new RestClient("http://localhost:8086/api/v1?table=categories&action=insert"); I have added this line to my c# imports ( I believe the library is actually called RestSharp rather than RestCharp) // Add 'using' directives here for all your event handlers. but getting this error message on building: include\tasklist_TableEvents.cs(16,7): error CS0246: The type or namespace name 'RestSharp' could not be found (are you missing a using directive or an assembly reference?) [C:\projects_v3\emailsendv112\output\emailsendv112.csproj] (same error with using RestCharp I am sure I am missing some very simple step - can anyone share with me what it might be ?! Many thanks |
|
Sergey Kornilov 12/2/2023 | |
Imports event is for adding "using" directives of libraries that are a part of core .NET package. If you need to use a third party DLL in your project check a link at the end of this article: |
D
|
david powell author 12/3/2023 |
Thanks Admin! I have added the RestSharp.dll ( and also NewtonSoftJson.dll and System.Net.Http which it also needs) to custom/bin/ directory. I have placed the following lines in the custom c# file And am almost there, but on building getting the following error messages Classes\XVar.cs(172,13): error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. [C:\projects_v3\emailsendv112\output\emailsendv112.csproj] ... and some others of the same nature. I cannot find any documentation as to adding references to assemblies in asprunner... where do I do that? I am building with visual studio 2019 and framework 4.8. Many thanks.... |
D
|
david powell author 12/3/2023 |
F
|
FR 2/2/2024 |
Did this ever get resolved? I will be needing to do this as well. |
Sergey Kornilov 2/2/2024 | |
In our tests it works right out of the box. |
D
|
david powell author 2/4/2024 |
Yes, I did get it to work, but using Newtonsoft and not RestSharp
using System; using System.Collections.Generic; using Newtonsoft.Json;
Bottom line is it does compile and work, and perhaps might be useful as a basis for you. string baseUrl = "https://xxxx.co.uk/api/v1/customers/test1"; try { // Parse JSON } |