Help with Ecom Express API Integration in My Project

Hey everyone! I’m having trouble getting the Ecom Express API to work in my project. I can get a JSON response in Postman when I try to fetch an AWB Number, but I can’t seem to replicate this in my code.

Here’s what I’ve tried so far:

<form id="shipForm">
  <input type="text" name="user" value="ecomuser" />
  <input type="text" name="pass" value="Tr@ck1ngP@ss" />
  <input type="text" name="qty" value="3" />
  <input type="text" name="mode" value="prepaid" />
</form>

<script>
function fetchAWB() {
  var formInfo = new FormData(document.getElementById('shipForm'));
  fetch('https://api.ecomexpress.com/v2/get_awb/', {
    method: 'POST',
    body: formInfo
  })
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
}
</script>

I’m using Razor v3. Any ideas what I’m doing wrong? Thanks!

I’ve worked with the Ecom Express API before, and there are a few things to consider. First, ensure you’re using the correct endpoint URL. The one in your code looks right, but double-check it against the official documentation.

Secondly, the API might require specific headers. Try adding ‘Content-Type’: ‘application/json’ to your fetch options. Also, some APIs prefer JSON data over FormData. You could try converting your form data to a JSON object and stringifying it.

Lastly, make sure your credentials are correct and that you have the necessary permissions. If you’re still stuck, I’d recommend reaching out to Ecom Express support. They can provide more specific guidance on integrating their API with Razor v3.

hey max, try adding req headers like ‘authorization’ and check if the api needs json instead of formdata. sometimes switching to axios helps. hope it fixes ur issue!

Hey Max_31Surf! Ecom Express can be tricky, huh? I ran into similar issues when I first started using their API. Have you considered using an API testing tool like Insomnia or Postman to compare your code’s request with a working one? It might help pinpoint where things are going wrong.

Also, I’m curious - are you getting any specific error messages when you try to run your code? Sometimes those can be super helpful in figuring out what’s not working.

Oh, and I noticed you’re using Razor v3. Are you integrating this with a specific backend framework? Sometimes the way you handle API calls can vary depending on your setup.

Keep us posted on how it goes! API integrations can be a real headache, but they’re so satisfying when you finally get them working.