SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-2110114%22%20slang%3D%22en-US%22%3EUpdate%20Group%20SharePoint%20Custom%20Field%20Collums%20after%20Fileupload%20with%20REST%20Graph%20API%20in%20Javascript%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2110114%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3CBR%20%2F%3EI've%20made%20an%20upload%20with%20Graph%20with%20the%20following%20JS%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Easync%20function%20uploadSingleFileMetaToSharepoint(file%2C%20name%2C%20metaData%2C%20groupId%2C%20graphAccessToken)%20%7B%0A%20%20%20%20%2F%2Fconsole.log(file%2C%20name%2C%20metaData%2C%20groupId)%3B%0A%20%20%20%20%2F%2FTODO%20get%20Filepath%20from%20config%20of%20App%0A%20%20%20%20let%20pathToFiles%20%3D%20'General'%0A%20%20%20%20let%20apiurl%20%3D%20msgraph%20%2B%20%60%2Fgroups%2F%24%7BgroupId%7D%2Fdrive%2Froot%3A%2F%24%7BpathToFiles%7D%2F%24%7Bname%7D%3A%2Fcontent%60%3B%0A%20%20%20%20if%20(debug)%20%7B%0A%20%20%20%20%20%20%20%20console.log(%22uploading%20File%3A%20%22%2C%20file)%3B%0A%20%20%20%20%20%20%20%20console.log(%60API-URL%3A%20%24%7Bapiurl%7D%60)%3B%0A%20%20%20%20%7D%0A%20%20%20%20let%20header%20%3D%20%7B%0A%20%20%20%20%20%20%20%20'Authorization'%3A%20graphAccessToken%2C%0A%20%20%20%20%7D%0A%20%20%20%20let%20body%20%3D%20file%3B%0A%20%20%20%20%2F%2FTODO%20catch%20errors%0A%20%20%20%20let%20result%20%3D%20await%20fetch(apiurl%2C%20%7B%0A%20%20%20%20%20%20%20%20%22method%22%3A%20'PUT'%2C%0A%20%20%20%20%20%20%20%20%22headers%22%3A%20header%2C%0A%20%20%20%20%20%20%20%20%22body%22%3A%20body%0A%20%20%20%20%7D)%3B%0A%20%20%20%20if%20(!result.ok)%20%7B%20console.error(%22upload%20file%20to%20sharepoint%20failed%22)%3B%20return%20%7D%0A%20%20%20%20let%20res%20%3D%20await%20result.json()%3B%0A%20%20%20%20%2F%2Fconsole.log(res)%3B%0A%20%20%20%20if%20(res%20%3D%3D%3D%20undefined%20%7C%7C%20res.id%20%3D%3D%3D%20undefined)%20%7Bconsole.error(%22Die%20DAtei%20wurde%20nicht%20hochgeladen%22)%3B%20return%3B%7D%0A%2F...%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3Bwhich%20is%20working%20fine.%3CBR%20%2F%3EBut%20now%20i'm%20struggling%20to%20fill%20the%20values%20of%20the%20collumns%20from%20sharepoint%20%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22yagcioe_0-1612193704744.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F251013i7843FAC0E0BC689F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22yagcioe_0-1612193704744.png%22%20alt%3D%22yagcioe_0-1612193704744.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EDoes%20anybody%20know%20how%20to%20approach%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2110114%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EGraph%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EJavaScript%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ERESTAPI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2110139%22%20slang%3D%22en-US%22%3ERe%3A%20Update%20Group%20SharePoint%20Custom%20Field%20Collums%20after%20Fileupload%20with%20REST%20Graph%20API%20in%20Javascript%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2110139%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F950609%22%20target%3D%22_blank%22%3E%40yagcioe%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3ENVM%20got%20it%20now%3A%3C%2FP%3E%3CP%3Ethe%20request%20abouve%20returns%20an%20item%20id%20and%20the%20group%20id%20is%20already%20know%2C%20therfore%26nbsp%3B%3CBR%20%2F%3EPATCH%20%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups%2F%7Bg-id%7D%2Fdrive%2Fitems%2F%7Bitem-id%7D%2FListItem%2Ffields%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups%2F%7Bg-id%7D%2Fdrive%2Fitems%2F%7Bitem-id%7D%2FListItem%2Ffields%3C%2FA%3E%3CBR%20%2F%3Eis%20working.%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20body%20of%20the%20request%20looks%20like%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%22FieldName%22%3A%22Value%22%2C%0A...%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
New 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 (New 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",
...
}