SOLVED

Update Group SharePoint Custom Field Collums after Fileupload with REST Graph API in Javascript

Copper Contributor

Hi,
I've made an upload with Graph with the following JS code:

 

 

 

async function uploadSingleFileMetaToSharepoint(file, name, metaData, groupId, graphAccessToken) {
    //console.log(file, name, metaData, groupId);
    //TODO get Filepath from config of App
    let pathToFiles = 'General'
    let apiurl = msgraph + `/groups/${groupId}/drive/root:/${pathToFiles}/${name}:/content`;
    if (debug) {
        console.log("uploading File: ", file);
        console.log(`API-URL: ${apiurl}`);
    }
    let header = {
        'Authorization': graphAccessToken,
    }
    let body = file;
    //TODO catch errors
    let result = await fetch(apiurl, {
        "method": 'PUT',
        "headers": header,
        "body": body
    });
    if (!result.ok) { console.error("upload file to sharepoint failed"); return }
    let res = await result.json();
    //console.log(res);
    if (res === undefined || res.id === undefined) {console.error("Die DAtei wurde nicht hochgeladen"); return;}
/...
}

 

 

 

 

 which is working fine.
But now i'm struggling to fill the values of the collumns from sharepoint :

yagcioe_0-1612193704744.png

Does anybody know how to approach this?

1 Reply
best response confirmed by yagcioe (Copper Contributor)
Solution

@yagcioe 
NVM got it now:

the request abouve returns an item id and the group id is already know, therfore 
PATCH https://graph.microsoft.com/v1.0/groups/{g-id}/drive/items/{item-id}/ListItem/fields
is working.

The body of the request looks like

{
"FieldName":"Value",
...
}
1 best response

Accepted Solutions
best response confirmed by yagcioe (Copper Contributor)
Solution

@yagcioe 
NVM got it now:

the request abouve returns an item id and the group id is already know, therfore 
PATCH https://graph.microsoft.com/v1.0/groups/{g-id}/drive/items/{item-id}/ListItem/fields
is working.

The body of the request looks like

{
"FieldName":"Value",
...
}

View solution in original post