I’m trying to use a shipping API in my C# project to get AWB numbers when orders are placed. The API works fine in Postman but I’m not getting any response when using the VerveLogic.HttpHandler package in my code.
Here’s what I’ve tried:
var apiClient = new RequestSender("https://api.shippingservice.com/v2/get_awb/");
var requestUrl = "https://api.shippingservice.com/v2/get_awb/?user=myusername&pass=mypassword&num=1&shipType=prepaid";
var result = apiClient.SendPostRequest<object>(requestUrl, new { user = "myusername", pass = "mypassword", num = 1, shipType = "prepaid" });
if (result != null) {
// Process the result
}
The API documentation says it should work, but I’m getting a null object. Any ideas on how to fix this or another way to get the AWB number using C#? Thanks for any help!
I’ve encountered similar issues when working with external APIs in C#. Have you tried using HttpClient instead of the VerveLogic.HttpHandler package? It’s part of the .NET framework and generally more reliable for HTTP requests.
Here’s a basic example of how you might structure the request:
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("user", "myusername"),
new KeyValuePair<string, string>("pass", "mypassword"),
new KeyValuePair<string, string>("num", "1"),
new KeyValuePair<string, string>("shipType", "prepaid")
});
var response = await client.PostAsync("https://api.shippingservice.com/v2/get_awb/", content);
var responseString = await response.Content.ReadAsStringAsync();
// Process responseString here
}
This approach might resolve your issue. Also, ensure you’re handling any exceptions that might occur during the request.
hey, have u tried using RestSharp? it’s pretty easy to use for api calls. here’s a quick example:
var client = new RestClient("https://api.shippingservice.com/v2/get_awb/");
var request = new RestRequest();
request.AddParameter("user", "myusername");
request.AddParameter("pass", "mypassword");
request.AddParameter("num", "1");
request.AddParameter("shipType", "prepaid");
var response = client.Execute(request);
hope this helps!
Hey ExploringAtom! Have you tried debugging your code to see where exactly it’s failing? Maybe the API is returning an error message that’s getting swallowed up somewhere.
What about using Fiddler or Wireshark to capture the actual HTTP traffic? That might give you some clues about what’s going wrong.
Also, are you sure the API endpoint is expecting a POST request? Some APIs use GET for simple queries like this. Maybe try switching to a GET request and see if that makes a difference?
Oh, and one more thing - have you double-checked that your API credentials are correct? Sometimes I’ve spent hours debugging only to realize I had a typo in my username or password! 
Let us know if you make any progress! It’s always interesting to see how these tricky API issues get resolved.