POST API call fails when using node js while the same call in curl is successful

Problem to solve

  • My javascript script for POST API call fails with the following error message (I’ve been using this script for publishing issues and there was no problem until today.):
  • Error Message: Request failed with status code 403
  </h1>
  <div class="container">
    <p>You are currently viewing from a blocked IP address or country.</p>

    Client IP: <MY_PUBLIC_IP>
    <br>
    Ray ID: xxxxxxx
    <br>
    Location: 
    <hr />
  </div>
</body>
</html>
Error Message:  Request failed with status code 403

Steps to reproduce

  • call node issueAPI.js returns error code 403.
  • While this curl call successfully created an issue.
 curl --request POST --header "PRIVATE-TOKEN: <MY_TOKEN>" \       
     --data "title=some title" \                  
     "https://gitlab.com/api/v4/projects/<MY_PROJECT_ID>/issues" 

Configuration

My script issue.API.js

const fs = require('fs');
const axios = require('axios');
const { projectId, accessToken } = require('./config');

// Read the Markdown file content
const descriptionContent = fs.readFileSync('description.md', 'utf-8');

// Define the API URL and your GitLab token
const url = `https://gitlab.com/api/v4/projects/${projectId}/issues`;
const token = accessToken;

const data = {
  title: 'some title',
  description: descriptionContent
};

const config = {
  headers: {
    'PRIVATE-TOKEN': token,
    'Content-Type': 'application/json'
  },
};

axios.post(url, data, config)
  .then(response => {
    console.log('Issue created:', response.data);
  })
  .catch(error => {
    console.error('Error creating issue:');
    console.error( 'Error Data: ', error.response.data);
    console.error('Error Message: ', error.message);
  });

Troubleshooting I’ve tried so far

  1. I’ve double-checked my project id and token. There is no question these are correct.

  2. Token scope: api, read_api, read_repository, write_repository

  3. netcat OK

$ nc -vz gitlab.com 443
Connection to gitlab.com port 443 [tcp/https] succeeded!
  1. ping OK
$ ping gitlab.com
PING gitlab.com (172.65.251.78): 56 data bytes
64 bytes from 172.65.251.78: icmp_seq=0 ttl=55 time=3.543 ms
64 bytes from 172.65.251.78: icmp_seq=1 ttl=55 time=11.485 ms
64 bytes from 172.65.251.78: icmp_seq=2 ttl=55 time=11.243 ms
64 bytes from 172.65.251.78: icmp_seq=3 ttl=55 time=10.636 ms
64 bytes from 172.65.251.78: icmp_seq=4 ttl=55 time=11.081 ms
  1. tried below following this similar post
curl http://gitlab.com/cdn-cgi/trace
curl https://gitlab.com/cdn-cgi/trace
curl -svo /dev/null https://gitlab.com

Results were all successful

fl=34f272
h=gitlab.com
ip=<my_public_ip>
ts=1727595351.286
visit_scheme=https
uag=curl/8.4.0
colo=ICN
sliver=none
http=http/2
loc=KR
tls=TLSv1.3
sni=plaintext
warp=off
gateway=off
rbi=off
  • traceroute gitlab.com:
traceroute gitlab.com
traceroute to gitlab.com (172.65.251.78), 64 hops max, 52 byte packets
 1  10.58.56.1 (10.58.56.1)  3.030 ms  1.933 ms  2.272 ms
 2  211.106.114.190 (211.106.114.190)  2.371 ms  2.875 ms  2.158 ms
 3  * * *
 4  * * *
 5  112.189.14.97 (112.189.14.97)  10.058 ms
    112.189.13.197 (112.189.13.197)  3.017 ms
    112.189.14.205 (112.189.14.205)  2.746 ms
 6  * * *

We encountered the same issue with a custom CLI tool that talks to the gitlab API.
We nailed it down to Axios 1.7.7. Using 1.7.6 from axios fixed the issue. Still don’t know what is causing this behaviour.

1 Like

Hi Karazy

Thank you so much!
I just tried your solution and it perfectly worked out. I was able to publish my issue using my script through the usual API call with node.

For future references for future community members, here are commands I tried:

  1. remove the entire node_modules, specify the axios version in your package.json and package-lock.json than reinstall.
npm list axios
rm -rf node_modules package-lock.json
npm install

Actually the approach 1) didn’t work for me, so I manually removed the axios module only and reinstalled it.

npm list axios                       ---------> 1.7.7
npm install axios@1.7.6
npm list axios                       ---------> 1.7.6
node issueAPI.js                  (my script for publishing issue, and it worked!)

Can I ask you though, what prompted you to suspect axios?
Are you also using axios and javascript for API?

I also struggled the whole morning with this issue. I’m using axios and javascript in a custom cli tool I wrote. In the last release I did an npm audit fix which updated axios. Basically it was trial and error in the end. :slight_smile:

Hi karazy!
Thank you so much for sharing your experience and insights.
I just found an issue tracker issue posted for the same issue that we both ran into. I left a comment to add my case and made a mention of you.

It looks like the problem is at a broader scale concerning conflicts between Gitlab API and axios.

Thanks a lot for adding the issue here and for mentioning me. :slight_smile: