adding zotero api to wordpress database

24 views
Skip to first unread message

Jennifer Lang

unread,
Oct 27, 2021, 11:20:02 PM10/27/21
to zotero-dev
Hello,

I am having trouble with the nesting on the zotero api when I try to enter my items into a wordpress database because all of these are inside a data array which is in another array.   Is there a way to only get the items in data:  Or do you know a way to write the function so it can recognize the nesting?

my api:

[
{
  "key": "XXXXXXX",
"version": XXXXXXX,"
library": {
            "type": "group","id": XXXXXXX,
"name": "Montessori",
"links": {"alternate": {"href": "https://www.zotero.org/groups/XXXXXX","type": "text/html"}}},"links": {"self": {"href": "https://api.zotero.org/groups/XXXXXX/items/XXXXXX",
"type": "application/json"},
"alternate": {"href": "https://www.zotero.org/groups/XXXXXX/items/XXXXXX",
"type": "text/html"}},
"meta": {
"createdByUser": {
"id": XXXXXX,
"username": "XXX","
name": "XXX",
"links": {"
alternate": {"href": "https://www.zotero.org/XXXX",
"type": "text/html"}}},"
creatorSummary": "Pesci",
"parsedDate": "2000",
"numChildren": 0},"
data": {
"key": "XXXXXX","version": XXXXX,
"itemType": 
"book",
"title": "L'attivismo rimosso: aspetti dell'educazione nuova tra Ottocento e Novecento",
"creators": [
{"creatorType": 
"author",
"firstName": "Furio"
,"lastName": "Pesci"
}
],
"abstractNote": "",
"series": "",
"seriesNumber": "",
"volume": "",
"numberOfVolumes": "",
"edition": "",
"place": "Torino",
"publisher": "Tirrenia Stampatori",
"date": "2000",
"numPages": "",
"language": "Italian",
"ISBN": "88-7763-4928", "shortTitle": "",
"url": "",
"accessDate": "",
"archive": "",
"archiveLocation": "","
libraryCatalog": "","
callNumber": "",
"rights": "",
"extra": "","
tags": [],
"collections": ["XXXXX"],
"relations": {},
"dateAdded": "2021-08-04T16:00:04Z","
dateModified": "2021-10-27T04:17:46Z"}},

Wordpress database function:

function save_database_table_info() {
global $wpdb;

$table_name = $wpdb->prefix . 'montessori_zotero_table_version';

$results = json_decode( get_option( 'montessori_zotero_api_info' ) );

foreach( $results as $result ) {

$wpdb->insert(
$table_name,
array(

//db columns        api names
// 'time' => current_time( 'mysql' ),
'itemType' => $result->itemType,
'title' => $result->title,
'creators' => $result->creators,
'abstractNote' => $result->abstractNote,
'series' => $result->series,
'seriesNumber' => $result->seriesNumber,
'volume' => $result->volume,
'numberOfVolumes' => $result->numberOfVolumes,
'editionArticle' => $result->editionArticle,
'publisher' => $result->publisher,
'dateArticle' => $result->date,
'numPages' => $result->numPages,
'languageArticle' => $result->language,
'ISBN' => $result->ISBN,
'shortTitle' => $result->shortTitle,
'urlArticle' => $result->url,
'accessDate' => $result->accessDate,
'archive' => $result->archive,
'archiveLocation' => $result->archiveLocation,
'libraryCatalog' => $result->libraryCatalog,
'callNumber' => $result->callNumber,
'rights' => $result->rights,
'extra' => $result->extra,
'tags' => $result->tags,
'collections' => $result->collections,
'relations' => $result->relations,

)
);

}
Reply all
Reply to author
Forward
0 new messages