I’m trying to get an AWB number from a shipping API in my C# code. The API works fine in Postman, but I’m getting a null object when using the VerveLogic.HttpHandler package.
Here’s what I’ve tried:
var apiClient = new WebRequest.Client("https://api.shippingservice.com/generate-awb");
var requestUrl = "https://api.shippingservice.com/generate-awb?user=myuser&pass=mypass&num=1&shipType=prepaid";
var result = apiClient.SendRequest<object>(requestUrl, new { user = "myuser", pass = "mypass", num = 1, shipType = "prepaid" });
if (result != null) {
// Process the result
}
The API documentation says it should return an AWB number, but I’m not getting any response. Has anyone successfully integrated this kind of shipping API in C#? Any tips on what I might be doing wrong or alternative approaches would be really helpful.
hey adventuroushiker76, have u tried using RestSharp? it’s pretty awesome for api stuff. here’s a quick example:
var client = new RestClient("https://api.shippingservice.com");
var request = new RestRequest("generate-awb", Method.GET);
request.AddParameter("user", "myuser");
// add other params
var response = client.Execute(request);
also, double-check ur api key. sometimes that’s the culprit. good luck!
Hey there, AdventurousHiker76! I’m curious about your shipping API integration. Have you checked if the API requires any specific headers? Sometimes these can be sneaky and cause issues.
Also, I wonder if the API might be expecting a different format for the parameters? Maybe try sending them in the request body instead of the URL:
var apiClient = new WebRequest.Client("https://api.shippingservice.com/generate-awb");
var requestBody = new { user = "myuser", pass = "mypass", num = 1, shipType = "prepaid" };
var result = apiClient.SendRequest<object>("POST", "", requestBody);
What kind of error handling do you have in place? It might be worth wrapping your API call in a try-catch block to see if any exceptions are being thrown.
Have you tried logging the raw response from the API? That could give you some clues about what’s going wrong.
Let us know what you find out – I’m really interested to see how you solve this!
I’ve encountered similar issues when working with shipping APIs. One thing that stands out is your use of the VerveLogic.HttpHandler package. While it’s convenient, I’ve found it can sometimes struggle with certain API structures.
Have you considered using HttpClient instead? It’s part of the .NET framework and often more reliable for these scenarios. 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();
// Parse content as needed
}
}
Additionally, verifying that your API credentials are correct and that you’re not hitting any rate limits might help, as APIs can behave differently in production compared to testing environments like Postman. Logging the raw response may also provide valuable insights into the issue.