0

I'm using the php SDK for microsoft graph to upload files to sharepoint. From time to time, the createRequest command hangs, and I'm not sure how to debug it. When I make a simple request, (e.g GET /me) it works.

        $graph = new Graph();
        $graph->setAccessToken($access_token);

        $user = $graph->createRequest("GET", "/me")
                      ->setReturnType(Model\User::class)
                      ->execute();

        // This works. $user is correct.

        /** @var Model\UploadSession $uploadSession */
        $uploadSession = $graph->createRequest("POST", "/drives/$drive_id/items/root:/$saveAsFileName:/createUploadSession")
            ->addHeaders(["Content-Type" => "application/json"])
            ->attachBody([
                "item" => [
                    "@microsoft.graph.conflictBehavior" => "rename",
                    "description" => $fileDescription
                ]
            ])
            ->setReturnType(Model\UploadSession::class)
            ->execute();

            // This line hangs
mankowitz
  • 1,864
  • 1
  • 14
  • 32
  • Your sample code works when I change from `POST` to `PUT`. With POST it returns an error when `name` is not provided. Do you get an error or the request never goes through? – Danstan May 24 '21 at 20:43

1 Answers1

0

I have tested this out using PHP SDK "microsoft/microsoft-graph": "^1.31" and I see that the create upload session works with PUT with your sample as is. For POST, the name field has to be provided. See below.

$drive_id = "drive-id";
$saveAsFileName = "sample.dat";

$body = [  
          "item" => [
              "@microsoft.graph.conflictBehavior" => "rename",
              "name" =>  $saveAsFileName
              ]
        ];

$response = $graph->createRequest("PUT", "/drives/$drive_id/items/root:/$saveAsFileName:/createUploadSession")
      ->addHeaders(["Content-Type" => "application/json"])
      ->attachBody($body)
      ->setReturnType(Model\UploadSession::class)
      ->execute();
Danstan
  • 1,501
  • 1
  • 13
  • 20
  • both the `$drive_id` and `$saveAsFilename` were defined. Also, if the url was incorrect, I would expect an error (e.g. malformed request), but I receive nothing back. The process just hangs. – mankowitz May 25 '21 at 11:57
  • Have you tried adding the name field to the body too? – Danstan May 25 '21 at 19:59