Hey everyone, I’m stuck with a shipping API integration. I’m trying to get an AWB number from this API, but I’m running into issues.
Here’s what I’ve tried:
var apiClient = new ShippingApiClient("https://api.example.com/v2/get-awb");
var requestUrl = "https://api.example.com/v2/get-awb?user=testuser&pass=testpass123&num=1&shipType=prepaid";
var result = apiClient.SendRequest<object>(requestUrl, new { user = "testuser", pass = "testpass123", num = 1, shipType = "prepaid" });
if (result != null) {
// Process the result
}
The weird thing is, it works fine in Postman but returns null when I use the C# code above. I’m using a NuGet package for HTTP handling.
Any ideas on how to fix this or a different way to get the AWB number using C#? Thanks in advance for any help!
Hey Mike_Energetic, shipping APIs can be tricky! Have you checked the API documentation for any specific authentication requirements? Sometimes they need tokens or special headers that aren’t obvious.
Also, are you sure the API is expecting a GET request? Maybe try switching to a POST if it’s not working:
var content = new StringContent(JsonConvert.SerializeObject(new { user = "testuser", pass = "testpass123", num = 1, shipType = "prepaid" }), Encoding.UTF8, "application/json");
var response = await client.PostAsync(requestUrl, content);
And hey, wild thought - could it be a firewall or network issue on your end? Sometimes corporate networks block weird ports or URLs.
Let us know if any of this helps or if you need more ideas!
I’ve encountered similar issues when integrating with shipping APIs. One thing to check is the content type and headers you’re sending. Some APIs are picky about this, even if Postman works fine. Try explicitly setting the content type to application/json and adding any required headers. Also, ensure you’re handling the response correctly—some APIs return non-standard formats that need custom deserialization. If that doesn’t work, you might want to try using HttpClient directly instead of a NuGet package. Sometimes lower-level control helps troubleshoot these issues. Here’s a basic example:
using (var client = new HttpClient())
{
var response = await client.GetAsync(requestUrl);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
// Process content here
}
}
Hope this helps point you in the right direction!
have u tried using httpclient directly? sometims those nuget packages can be finicky. heres a quick example:
using var client = new HttpClient();
var response = await client.GetAsync(requestUrl);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
// do stuff with content
}
this might help u pinpoint where the issue is. good luck!