Onedrive has stopped creating folders

Copper Contributor

I have recently implemented the Graph api to:

create in a shared folder various directories with names like this => "uc_123455";
on each folder created, the api upload pdfs inside it ;

the problem:

it starts ok but after a time it just stop creating folder, it has a total of almost 3500 folders to create and stops after 1000.

the code works like this:

it first get the access_token from microsoft and load the Graph then get the shared folder ID

$this->graph = new Graph();
$this->graph->setAccessToken($this->accessToken);
$this->directory_id = $this->fetchDirectoryId($this->graph);

then i start looping:

first it create the name based on what part is of the loop

$subfolderName = "UC_" . $customer->numero_uc;

after this is used to create the folder on this function

$folder = $this->createIntoDirectory($this->directory_id[0], $this->graph, $subfolderName);

and this function works like this

public function createIntoDirectory(string $folderId, Graph $graph, string $ucNumber): string|bool
{
try {
$response = $graph->createRequest('POST', "/me/drives/" . $this->drive_id . "/items/$folderId/children")
->attachBody(json_encode([
"name" => $ucNumber,
"folder" => new stdClass()
], JSON_THROW_ON_ERROR))
->setReturnType(DriveItem::class)
->execute();
return $response->getId();
} catch (GuzzleException|GraphException) {
return $this->fetchExistenteDirectory($folderId, $graph, $ucNumber);
}
}

if already exist an Folder with the name it falls in the exception and call to another function that return the id of the already created folder (I did this in case any pdfs weren't sent to the folder)

heres the function:

public function fetchExistenteDirectory(string $folderId, Graph $graph, string $ucNumber): string|bool
{
try {
$folder = $graph->createRequest('GET', "/me/drives/" . $this->drive_id . "/items/$folderId/children")
->setReturnType(DriveItem::class)
->execute();
foreach ($folder as $item) {
if ($item->getName() === $ucNumber) {
return $item->getId();
}
}
return false;
} catch (GuzzleException|GraphException) {
return false;
}
}

are there problems with my code to stop generation folders? because it works 100% fine, until then it stops

questions like: where is the pdf? the pdf are converted images from urls that i fetch from my db

what is UC: is like users, it come from portuguese word "unidade consumidora" or "consumer unit", each of then come from an array that i fetch from my db

if it has any questions about the code or the process just ask.

Thanks

(english isn't my mother tongue, so sorry for any grammatical error)

0 Replies