Created
April 24, 2024 14:31
-
-
Save diego-lipinski-de-castro/bfd42348f6d8dd3b9b357c495db40c09 to your computer and use it in GitHub Desktop.
código php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mutation = <<<GQL | |
mutation CreateFolderMutation( | |
\$folder: FolderInput! | |
) { | |
createFolder( | |
folder: \$folder | |
) { | |
id | |
name | |
created_at | |
} | |
} | |
GQL; | |
// Setup cURL | |
$ch = curl_init($this->config->get('base_url')); | |
// Set up the payload | |
$payload = [ | |
'operations' => json_encode([ | |
'query' => $mutation, | |
'variables' => [ | |
'folder' => [ | |
'name' => $folderName, | |
], | |
], | |
]), | |
]; | |
// Set cURL options | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); | |
// Add headers including the Bearer token | |
curl_setopt($ch, CURLOPT_HTTPHEADER, [ | |
'Authorization: Bearer ' . $this->config->get('token'), | |
]); | |
// Execute the cURL session | |
$response = curl_exec($ch); | |
// Error handling | |
if (curl_errno($ch)) { | |
Log::channel('autentique')->debug('Error:' . curl_error($ch)); | |
return null; | |
} | |
// Close cURL session | |
curl_close($ch); | |
// Print response from the server | |
$data = json_decode($response, true); | |
dd($data); | |
return $data['data']['createFolder']['id']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment