HTTP POST request body not being sent in Zapier Code action

I’m having trouble with Zapier’s Code functionality when trying to send a POST request. The request seems to go through but the body content appears to be missing when I check what gets sent to the server.

I’ve double checked the documentation and my code looks right to me, but something isn’t working. The server isn’t receiving any of the data I’m trying to send.

Here’s what I’m using:

var apiUrl = 'https://myapi.example.org/webhook';
var requestData = {
  'records': [
    {
      'timestamp': '2024-01-15',
      'count': '5'
    }
  ],
  'formatting': {
    'count': '#ff6b35'
  }
};

fetch(apiUrl, {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify(requestData)
}).then(function(res) {
  return res.text();
}).then(function(data) {
  var result = {output: data};
  callback(null, result);
}).catch(function(err) {
  callback(err);
});

Anyone know what might be causing this issue?

I ran into this exact same problem a few months back and it drove me crazy for hours. The issue is likely that you’re using the old-style callback pattern in your Zapier code action. Zapier’s newer runtime doesn’t always handle the callback properly with async operations like fetch. Try converting your code to use async/await instead of the callback pattern. Replace your fetch chain with something like this:

const response = await fetch(apiUrl, {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify(requestData)
});

const data = await response.text();
return {output: data};

Also make sure your function is declared as async. This solved the body transmission issue for me completely. The callback approach seems to have timing issues that prevent the request body from being properly serialized before the request is sent.

Had a similar headache with Zapier Code actions recently. One thing that caught me off guard was that Zapier sometimes has issues with certain JSON structures in the request body. Try simplifying your requestData object first to see if the basic POST works, then gradually add complexity back. Also, I noticed you’re using string values for your count field - depending on your API endpoint, it might expect integers. Another debugging approach that helped me was adding some console.log statements before the fetch call to verify the JSON.stringify output actually contains what you expect. Sometimes the issue isn’t with the transmission but with how the data gets structured before sending.

check if your zapier account has the right permissions for external api calls. sometimes the body gets stripped if theres a security restriction. also try adding a user-agent header - some apis reject requests without it which might make it seem like the body isnt being sent when really the whole request is being blocked.