1

I'm using microsoft graph api to interview with sharepoint.

  1. Upload file to sharepoint.

    https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/drive/root:/test1212123.txt:/content

  2. Then we can got the response.

     {
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('abc78c05-a77b-45bf-a1a1-51f09548b497')/drive/root/$entity",
    "@microsoft.graph.downloadUrl": "https://yeeofficesg.sharepoint.com/sites/GdTest/_layouts/15/download.aspx?UniqueId=b9d25e13-c915-432f-b9fb-f2d36a188d9f&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAveWVlb2ZmaWNlc2cuc2hhcmVwb2ludC5jb21AMzgzMDNhNTQtMjUwMS00MDcwLTlkYjItYzNmNTY2OTc2NGUxIiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTU4NDY4MjQ5OSIsImV4cCI6IjE1ODQ2ODYwOTkiLCJlbmRwb2ludHVybCI6InltcjVvWHhDU0FIaFhhV0tYVnZuVDVjK05ETnZsejhzcC9YeFp3MStQaHc9IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxMzUiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6IlpUUmhPVFk1WkdFdE5EQXlOQzAwWlRnMExUazFZelF0WkRkalpqRmpOR1UxTm1ZMCIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJZV0pqTnpoak1EVXRZVGMzWWkwME5XSm1MV0V4WVRFdE5URm1NRGsxTkRoaU5EazMiLCJhcHBfZGlzcGxheW5hbWUiOiJIdHRwUmVxdWVzdCBUZXN0IiwibmFtZWlkIjoiNTk3ZDQ4YmMtMDVmMy00MTU4LThhY2MtYWU1Y2M3YTljNmFkQDM4MzAzYTU0LTI1MDEtNDA3MC05ZGIyLWMzZjU2Njk3NjRlMSIsInJvbGVzIjoiYWxsc2l0ZXMud3JpdGUgYWxsZmlsZXMud3JpdGUiLCJ0dCI6IjEiLCJ1c2VQZXJzaXN0ZW50Q29va2llIjpudWxsfQ.aTVxeDdWNkowcWFDK0xYOHUvZGo3K0VVSEd1dU02MFVheEFJbnBWWUJHTT0&ApiVersion=2.0",
    "createdDateTime": "2020-03-20T05:34:59Z",
    "eTag": "\"{B9D25E13-C915-432F-B9FB-F2D36A188D9F},1\"",
    "id": "016REKDTITL3JLSFOJF5B3T67S2NVBRDM7",
    "lastModifiedDateTime": "2020-03-20T05:34:59Z",
    "name": "test1212123.txt",
    "webUrl": "https://yeeofficesg.sharepoint.com/sites/GdTest/Shared%20Documents/test1212123.txt",
    "cTag": "\"c:{B9D25E13-C915-432F-B9FB-F2D36A188D9F},1\"",
    "size": 12,
    "createdBy": {
        "application": {
            "id": "597d48bc-05f3-4158-8acc-ae5cc7a9c6ad",
            "displayName": "HttpRequest Test"
        }
    },
    "lastModifiedBy": {
        "application": {
            "id": "597d48bc-05f3-4158-8acc-ae5cc7a9c6ad",
            "displayName": "HttpRequest Test"
        }
    },
    "parentReference": {
        "driveId": "b!BYzHq3unv0WhoVHwlUi0l_EO2rYM2NNCptmOTvJ-EqeM9aeJ-zj_TZktSrctfA1S",
        "driveType": "documentLibrary",
        "id": "016REKDTN6Y2GOVW7725BZO354PWSELRRZ",
        "path": "/drive/root:"
    },
    "file": {
        "mimeType": "text/plain",
        "hashes": {
            "quickXorHash": "RBBCDGQwAxrUIARAFAEJSgAAAAA="
        }
    },
    "fileSystemInfo": {
        "createdDateTime": "2020-03-20T05:34:59Z",
        "lastModifiedDateTime": "2020-03-20T05:34:59Z"
    }
    }
    
  3. Then I want to update the customized column of this list. https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff-992d-4ab72d7c0d52/items/80/fields

  4. step3, I needs the item id (this example is : 80) but when I upload the file, I can't got the item id directly from the response.

use this api:https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff-992d-4ab72d7c0d52/items/ I can got the items list which include the item id is needed.

Finally, my question is ,when I upload file to sharepoint, how can I got the item id which is needed by update item.

1 Answer 1

1

I ended up extracting the Item GUID from the response, i.e.

"@microsoft.graph.downloadUrl": "https://yeeofficesg.sharepoint.com/sites/GdTest/_layouts/15/download.aspx?UniqueId=b9d25e13-c915-432f-b9fb-f2d36a188d9f&Translate=false&tempauth=....

or

"eTag": ""{B9D25E13-C915-432F-B9FB-F2D36A188D9F},1""

or

"cTag": ""c:{B9D25E13-C915-432F-B9FB-F2D36A188D9F},1""

And then use that in the PATCH call where the item ID is required, i.e. https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff-992d-4ab72d7c0d52/items/**B9D25E13-C915-432F-B9FB-F2D36A188D9F**/fields

Might be a more elegant way to solve the problem, however this worked for me

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.