API v3 Update file endup with 404 not found [SOLVED]


In some html page (on firefox) i try to call the update file API using fetch :

<!DOCTYPE html>

<meta charset="utf-8" />
<script src="lib/sha1.js"></script>
    let content = "This is a test";
    let base64content = window.btoa(content);
    let contentSha1=window.sha1(content);

    let owner = "manaty";
    let repo = "michea.github.io";

    let username="manaty"
    let token="75******************************149b72ba";

    fetch("https://api.github.com/repos/" + owner + "/" + repo + "/contents/pos/data/catalog/products.csv", {
        method: 'PUT',
        mode: 'cors',
        body: {
            "path": "products.csv",
            "message": "update product list",
            "content": base64content,
            "sha": contentSha1
        headers: {
            'User-Agent': username,
            'Accept': 'application/vnd.github.v3+json',
            'Authorization': 'token ' + token
        .then(response => response.text()).then(resp => { alert("pushed file:" + resp) })

but i receive a 404 error with body {“message”:“Not Found”,“documentation_url”:“https://developer.github.com/v3/repos/contents/#update-a-file”}

i tried with several github personal tokens, i tried to either create or update a file (by the way i didnt see what is the difference between the create and update file api), i tried with chrome,… cant get a clue.

here is the request sent:

could it be be because Authorization header was transformed to lowercase by firefox , and User-Agent overriden by chrome ?

Thank you in advance for your help

Edit: This was just a permission pb (the token had no rights on repo" but i didnt detect it by the method described in the doc,
by performing the following 2 requests, first with incorrect token and second with correct token, gave the same answer:

curl -H @{'Authorization'='token 752*******************ba'} https://api.github.com/users/manaty

StatusCode        : 200
StatusDescription : OK
Content           : {"login":"manaty","id":2926051,"node_id":"MDQ6VXNlcjI5MjYwNTE=","avatar_url":"https://ava
RawContent        : HTTP/1.1 200 OK
                Status: 200 OK
                X-RateLimit-Limit: 5000
                X-RateLimit-Remaining: 4999
                X-RateLimit-Reset: 1535672621
                Vary: Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding
Forms             : {}
Headers           : {[Status, 200 OK], [X-RateLimit-Limit, 5000], [X-RateLimit-Remaining, 4999],
                [X-RateLimit-Reset, 1535672621]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 1146


Just a drive-by guess, but shouldn’t the path in the body of your request be pos/data/catalog/products.csv, not just products.csv?


Thank you for spotting that. I tried to change, but got same result.