Hi
I am exploring options to extract metadata from an article/submission hosted on OJS using REST API. I have written a script in PHP and it could not extract the metadata (see the script below). I was wondering if anyone has developed or come across a script specifically designed for this purpose? Specifically, I’m interested in obtaining metadata fields such as title, authors, abstract, keywords, publication date, etc.
Any guidance, scripts (PHP/Python), or recommendations would be highly appreciated.
Thank you for your assistance!
-Obi
<?php
// OJS base URL and API endpoint
$baseUrl = ‘https://james.uit.no/ojs3404’; // Replace with your OJS base URL
$apiEndpoint = ‘/index.php/testA/api/v1/submissions/6545/publications’; // Replace {joural_id} and {article’s submission_id} with the actual journal ID and Sumbission ID respectively
// API authentication headers
$headers = [
‘Authorization: eyJ0eXAixxxxxxxxx’, // Replace with your API key if required
‘Content-Type: application/json’
];// Initialize cURL session
$ch = curl_init();// Set cURL options
curl_setopt($ch, CURLOPT_URL, $baseUrl . $apiEndpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);// Execute cURL session and fetch response
$response = curl_exec($ch);// Check if cURL request was successful
if (curl_errno($ch)) {
echo 'Error occurred: ’ . curl_error($ch);
} else {$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo “$httpCode. \n”;
// Decode JSON response
$articleMetadata = json_decode($response, true);// Extract relevant metadata (adjust based on your requirements) $title = $articleMetadata['title'] ?? 'N/A'; $authors = array_column($articleMetadata['authors'] ?? [], 'name'); $abstract = $articleMetadata['abstract'] ?? 'N/A'; // Output extracted metadata echo "Title: {$title}\n"; echo "Authors: " . implode(', ', $authors) . "\n"; echo "Abstract: {$abstract}\n";
}
// Close cURL session
curl_close($ch);?>