0

I am trying to update a gist through the GitHub API. I first ran this command in my terminal:

curl -H "Authorization: token xxxxxxxxxx" -X PATCH -d '{"files": {"InputFile.txt": {"content": "LMAO YEET"}}}' https://api.github.com/gists/xxxxxxxxxx

This command ran with no errors, and my Gist was updated.

However, I ran into a problem when I tried to execute this code in java:

Process proc = Runtime.getRuntime().exec("curl -H \"Authorization: token xxxxxxxxxx\" -X PATCH -d '{\"files\": {\"InputFile.txt\": {\"content\": \"LMAO YEET\"}}}'  https://api.github.com/gists/xxxxxxxxxx");

Running this code gave me a 404 not found error. It would be great if someone could explain why this is happening and if there is a workaround for it.

Thanks in advance!

PS: I know there is a Java API library, but I want to stick to Java's native libraries for now

PPS: Some information have been changed to "xxxxxxxxxx" for obvious reasons.

  • 404 means not found, so GitHub can't find the gist you want to access. You might want to double check the requests you wan to perform. Maybe there are underling issues with your way of executing the request. – Florian Hergenhahn May 13 '20 at 10:06
  • Code looks good hence the problem has to be in your request URL – QuickSilver May 13 '20 at 10:43
  • No, the URL is fine. I copy-pasted it into the browser and got the .json file. Also, I removed the PATCH request and it returned the .json too. – Muhammad Mohsin May 13 '20 at 10:57
  • @MuhammadMohsin can you maybe post the error message? – Florian Hergenhahn May 13 '20 at 11:43
  • error message: { "message": "Not Found", "documentation_url": "https://developer.github.com/v3/gists/#edit-a-gist" } after I add in -i option in curl, the Status entry says '404 Not Found' – Muhammad Mohsin May 13 '20 at 13:44
  • Oh, also, I put the same command (with a little changes for the json input) in my windows virtual machine, and it worked like a charm. I also ran this command using a Python script in my mac, and it worked fine too. Probably its a Mac+Java only problem? – Muhammad Mohsin May 13 '20 at 13:48
  • @MuhammadMohsin, yes it might be. Try using the `ProcessBuilder` and see if you are getting a different result. Source: https://stackoverflow.com/questions/6856028/difference-between-processbuilder-and-runtime-exec – Florian Hergenhahn May 13 '20 at 15:49
  • Got the same not found error. Here's what I did: String command = "curl -H \"Authorization: token xxxxxxxxxx\" -X PATCH -d '{\"files\": {\"InputFile.txt\": {\"content\": \"yeeter meeter\"}}}' https://api.github.com/gists/xxxxxxxxxx"; Process Proc = new ProcessBuilder(command.split(" ")).start(); The URL is right, I've checked it. – Muhammad Mohsin May 13 '20 at 16:52

0 Answers0