I coded up a Restsharp call to Bitly's APIs and it worked. I received back the numbered HTTP StatusCode in the 200, 300, 400, and 500 ranges.
Now that switched over to using the BitlyAPI Nuget package, I am getting a string status condition back of RanToCompletion or WaitingForActivation. The code works, but--
1. Is there a way to get the numbered Http-StatisCode still through the BitlyAPI PostShorten (GetResponse) code?
2. If not, what are all the status-phrases we may get from GetResponse and what status-codes' are they equivalent to? I have looked for a documented list for this, but not found one yet.
I need to be able to recognize API communication issues and setup potential corrective actions.
Thanks!
using System;
using System.Threading.Tasks;
using BitlyAPI;
namespace ConsoleAPITester
{
internal class Program
{
static void Main(string[] args)
{
string authcode = "xyz123";
string domain = "somecompany.com";
string groupguid = null;
string longurl = @"https://example.com";
CallShorten(authcode,longurl, domain, groupguid);
}
public static async void CallShorten(string authcode, string longurl, string domain, string groupguid = null)
{
BitlyAPI.Bitly BPI = new BitlyAPI.Bitly(authcode);
Task<BitlyLink> response = BPI.PostShorten(longurl, groupguid, domain);
response.Wait();
Console.WriteLine("Status:" + response.Status);
Console.WriteLine("Result:created_at:" + response.Result.CreatedAt);
Console.WriteLine("Result:id:" + response.Result.Id);
Console.WriteLine("Result:link:" + response.Result.Link);
}
}
}
Last three lines from GetResponse method (called by PostShorten) in BitlyAPI Bitly class obtained from "go to definition" in VS2022. I'm guessing the shift from HttpStatusCode to Status(phrase) is in EnsureSuccessStatusCode ?
HttpResponseMessage obj = await httpClient.SendAsync(request).ConfigureAwait(continueOnCapturedContext: false);<br/>
obj.EnsureSuccessStatusCode();<br/>
return JsonConvert.DeserializeObject<T>(await obj.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false));<br/>
OUTPUT:
Status:RanToCompletion
Result:created_at:2023-04-25T17:44:40+0000
Result:id:somecompany.com/xyz123
Result:link:https://somecompany.com/xyz123