Help needed with Ecom Express API integration in my project

Hey everyone! I’m stuck trying to get Ecom Express APIs working in my project. I can get the AWB Number fine in Postman, but when I try to do it in my code, I’m not getting any response. Here’s what I’ve got so far:

<form id="shipForm" name="shipForm" enctype="multipart/form-data">
    <input type="text" id="user" name="user" value="ecomuser" />
    <input type="text" id="pass" name="pass" value="Sh1pp1ng@123" />
    <input type="text" id="quantity" name="quantity" value="3" />
    <input type="text" id="mode" name="mode" value="prepaid" />
</form>

<script>
function fetchAWBNumber() {
    var formInfo = new FormData($('#shipForm')[0]);
    $.ajax({
        url: 'https://api.ecomexpress.com/v2/get_awb/',
        type: 'POST',
        data: formInfo,
        dataType: 'json',
        cache: false,
        contentType: false,
        processData: false,
        success: function (response) {
            console.log(response);
        }
    });
}
</script>

I’m using Razor v3 for this. Any ideas what I’m doing wrong? Thanks in advance for your help!

I’ve encountered similar issues with Ecom Express integration. One thing to consider is the Content-Type header. Even though you’re using FormData, try explicitly setting it to ‘application/x-www-form-urlencoded’. Also, ensure your API endpoint is correct - sometimes the live and test environments have slightly different URLs.

Another potential issue could be related to CORS. If you’re developing locally, you might need to set up a proxy server to bypass CORS restrictions. This is often necessary when working with third-party APIs.

Lastly, double-check your API credentials. It’s easy to overlook, but sometimes credentials that work in Postman might not be properly configured for your development environment.

If none of these solve the problem, you might want to reach out to Ecom Express support. They often have specific requirements or known issues that aren’t immediately apparent from the documentation.

hey daisy! i’ve dealt with ecom express before. have u tried using fetch instead of ajax? it’s easier to handle promises. also, make sure ur api key is valid for the environment ur using. sometimes they differ between test and production. lemme know if u need more help!

Hey Daisy_Whimsical! I’ve been tinkering with Ecom Express APIs too, and I feel your pain. Have you checked if you’re getting any error messages in the console? Sometimes those can be super helpful in pinpointing what’s going wrong.

Also, I’m curious - are you testing this locally or on a live server? I ran into issues when I was working locally due to CORS restrictions. Maybe try adding an error callback to your AJAX call? Something like:

error: function(xhr, status, error) {
    console.error(xhr.responseText);
    console.error(status);
    console.error(error);
}

This might give you more insight into what’s happening behind the scenes.

Oh, and just a thought - have you double-checked that your API credentials are correct in the actual environment you’re running this in? Sometimes what works in Postman doesn’t translate 1:1 to our code.

Let me know if any of this helps or if you need more ideas! What kind of project are you working on, by the way?