I am trying to post an issue via the API but I keep getting a 404 error. This is my code:
import requests
r = requests.post(r "https://<my_organization_url>/api/projects/278/issues", data = {
"title": "hello",
"description": "world"
},
headers = {
"PRIVATE-TOKEN": "<my private key>"
})
print(r.status_code, r.reason)
Any ideas? I have checked and this project does in fact exist, I got the ID from the top of its page.
Could you give us the actual output of your print
statement?
Other than that, the first thing that caught my eye was the fact that you are not specifying the API version. I’d suggest adding /v4/
to the URL:
- r = requests.post(r "https://<my_organization_url>/api/projects/278/issues", data = {
+ r = requests.post(r "https://<my_organization_url>/api/v4/projects/278/issues", data = {
In fact, you can just try this from the command line to confirm. This request does not seem to require authentication:
curl "https://<my_organization_url>/api/v4/projects/<my_project_id>/issues"
As per the GitLab API documentation:
API requests should be prefixed with api and the API version. […] For example, the root of the v4 API is at /api/v4
.
Example of a valid API request using cURL:
curl "https://gitlab.example.com/api/v4/projects"
I hope this helps!
Adding v4
worked, thanks. I was confused though because I saw a support post elsewhere (seem to have lost the URL) that indicated that you should no longer specify the version number in the URL. Anyway this works, so thank you.
1 Like
Excellent, glad it worked! Please feel free to mark the answer as solving your issue then (the small checkbox at the bottom of each post’s actions). That helps other community members to quickly find the solution if they are experiencing the same or similar issues.
Thanks!