Function seeing axios.post as GET request

Hey there,

I started seeing issues with my function not working and I think I’ve narrowed down the issue to how my function is receiving my request once I POST to it.

Netlify function
Github: GitHub - colbyfayock/tweet: Netlify function to post a tweet to Twitter!
Site: https://tweet-with-twitter.netlify.app/

Code calling function
Github: amazon-goldbox/rss.js at master · colbyfayock/amazon-goldbox · GitHub
Snippet:

    await axios.post('https://tweet-with-twitter.netlify.com/.netlify/functions/tweet', payload, {
      headers: {
        Authorization: token
      }
    });

When running this locally, there doesn’t seem to be any problems with my payload, it fires and returns a 200. However, when POSTing the exact same code to the deploy function, the body appears to be empty. I confirmed this with logs to debug the function.

To debug that, I console.log’ed the event itself, and it turns out on Netlify, my function is receiving that POST as a GET:

    INFO	event {
      path: '/.netlify/functions/tweet',
      httpMethod: 'GET',
      headers: {

Locally:

    Request from ::ffff:127.0.0.1: POST /tweet

Any thoughts about what’s going on here? I was originally running the function on node v8, but I updated the .nvmrc to v12 and tested locally with the same version (in both instances). Still the same issue.

Thanks

Hi @colbyfayock, I tried invoking your function using insomnia and if you check your function logs, it does show the httpMethod as POST. Could you try using the object method like below?

axios({
  method: 'post',
  url: 'http://bit.ly/2mTM3nY',
  data: <body here>
}) 

Let me know if that works.

I tried updating to that format and testing locally and still only seem to get a GET which is bizarre…

await axios({
  method: 'post',
  url: 'https://tweet-with-twitter.netlify.com/.netlify/functions/tweet',
  data: payload,
  headers: {
    'Authorization': token
  }
});

I did however try to POST with fetch just to test and it seems to go through as a POST but just having trouble getting the formatting to take in the payload right :thinking: so maybe it’s an issue between axios and the serverless framework which i’m using for the app?

The strange thing is that it works on my locally served netlify function (localhost:9000) but not when posting directly there.

await axios({
  method: 'post',
  url: 'http://localhost:9000/tweet',
  // url: 'https://tweet-with-twitter.netlify.com/.netlify/functions/tweet',
  data: JSON.stringify(payload),
  headers: {
    'Authorization': token
  }
});

Anyways, I’ll either use a different tool or keep digging.

Thanks

1 Like

I think I’m having a similar issue, did you tried Postman or node-fetch ?

Hi everyone! I have a similar issue, I get no response or error when axios request after deploying on Netlify

my request :

axios({
method: ‘get’,
url: ‘https://funcs-lab.netlify.app/.netlify/functions/coucou’,
})

        .then((response) => {
            console.log("response: ", response);
           
        }).catch(error => {
        console.log("erreur: ", error);
    });

And when I use node-libcurl :

const {curly} = require(‘node-libcurl’);
const { statusCode, data, headers } = await curly.post(‘https://funcs-lab.netlify.app/.netlify/functions/coucou’, {
postFields: querystring.stringify(params),
httpHeader: [
‘Accept: text/xml’
],
})

console.log("data: " ,data)

I get this error after deploying on netlify

6:27:34 AM: 896f1fbc ERROR Invoke Error {“errorType”:“Error”,“errorMessage”:“Problem with the SSL CA cert (path? access rights?)”,“code”:77,“isCurlError”:true,“stack”:[“Error: Problem with the SSL CA cert (path? access rights?)”]}

@colbyfayock Have you fix it ?

Thanks

Hey there, @bangaromaric :wave:

Sorry to hear you are having this issue. I see that you also commented in this thread as well. Let’s keep your responses on the other thread to streamline conversation and support. I assure you we haven’t forgotten about it yet!

Thanks for understanding :slight_smile: