how to get the complete structure of JSONAPI

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
mahmoud
Posts: 29
Joined: 27 Mar 2020, 22:01

how to get the complete structure of JSONAPI

Post by mahmoud » 09 Sep 2024, 00:41

Hi,
I'm using aimeos/aimeos-headless to create my e-commerce with vue 3 and Typescript , to handle the code i created a types.ts file with the structure like below from the like https://aimeos.org/docs/2024.x/frontend/jsonapi/, but that not compete and manually, can you give me the complete jsonAPI structure of aimeos.
thank you

Code: Select all

// src/types.ts
// catalog (categories)
// product
// service
// attribute
// media
// price
// text 
// src/types.ts
// Meta interface
export interface Meta {
  total?: number;
  prefix?: null | string;
  "content-baseurl": string;
  csrf?: {
    name: string;
    value: string;
  };
}

// SelfLink interface
export interface SelfLink {
  href: string;
  allow: string[];
}

// Site interface
export interface Site {
  id: string;
  type: string;
  attributes: {
    "locale.site.id": string;
    "locale.site.code": string;
    "locale.site.icon": string;
    "locale.site.logo": { [key: string]: string };
    "locale.site.theme": string;
    "locale.site.label": string;
    "locale.site.status": number;
    "locale.site.refid": string;
    "locale.site.hasChildren": boolean;
    "locale.site.ratings": number;
    "locale.site.rating": string;
  };
}

// Locale interface
export interface Locale {
  id: string;
  attributes: {
    "locale.id": string;
    pos: number;
    site_id: number;
    "locale.currencyid": string;
    "locale.languageid": string;
    "locale.position": number;
    "locale.sitecode": string;
    "locale.siteid": string;
    "locale.status": number;
  };
}

// BasketProductLink interface
export interface BasketProductLink {
  href: string;
  allow: string[];
}

// ProductJsonResponse interface
export interface ProductJsonResponse {
  meta: Meta;
  links: Links;
  data: ProductData[];
  included?: IncludedItem[];
}

// ProductData interface
export interface ProductData {
  id: string;
  type: string;
  links: {
    self: SelfLink;
    "basket/product": BasketProductLink;
  };
  attributes?: ProductAttributes;
  relationships?: DataRelationships;
}

// IncludedItem interface
export interface IncludedItem {
  id: string;
  type: string;
  attributes?: CatalogAttributes | MediaAttributes | TextAttributes | StockAttributes;
  relationships?: DataRelationships;
  links?: {
    self: SelfLink;
  };
}

// ProductAttributes interface
export interface ProductAttributes {
  "product.id": string;
  "product.url": string;
  "product.type": string;
  "product.code": string;
  "product.label": string;
  "product.status": number;
  "product.dataset": string;
  "product.datestart": string | null;
  "product.dateend": string | null;
  "product.config": any[]; // Adjust type as needed
  "product.scale": number;
  "product.target": string;
  "product.ctime": string;
  "product.ratings": number;
  "product.rating": string;
  "product.instock": number;
}

// DataRelationships interface
export interface DataRelationships {
  catalog: {
    data: CatalogData[];
  };
  media: {
    data: MediaData[];
  };
  text: {
    data: TextData[];
  };
  stock: {
    data: StockData[];
  };
}

// CatalogData interface
export interface CatalogData {
  id: string;
  type: string;
  attributes: CatalogAttributes;
  relationships?: {
    media: {
      data: MediaData[];
    };
    text: {
      data: TextData[];
    };
    stock: {
      data: StockData[];
    };
  };
}

// CatalogAttributes interface
export interface CatalogAttributes {
  "catalog.url": string;
  "catalog.code": string;
  "catalog.label": string;
  "catalog.config": any[]; // Adjust type as needed
  "catalog.status": number;
  "catalog.target": string;
  "catalog.hasChildren": boolean;
}

// MediaData interface
export interface MediaData {
  id: string;
  type: string;
  attributes: MediaAttributes;
}

// MediaAttributes interface
export interface MediaAttributes {
  "media.id": string;
  "media.filesystem": string;
  "media.domain": string;
  "media.label": string;
  "media.languageid": null;
  "media.mimetype": string;
  "media.type": string;
  "media.preview": string;
  "media.previews": Record<string, string>;
  "media.url": string;
  "media.status": number;
}

// TextData interface
export interface TextData {
  id: string;
  type: string;
  attributes: TextAttributes;
}

// TextAttributes interface
export interface TextAttributes {
  "text.id": string;
  "text.languageid": null;
  "text.type": string;
  "text.label": string;
  "text.domain": string;
  "text.content": string;
  "text.status": number;
}

// StockData interface
export interface StockData {
  id: string;
  type: string;
  attributes: StockAttributes;
  links: {
    self: SelfLink;
  };
}

// StockAttributes interface
export interface StockAttributes {
  "stock.id": string;
  "stock.productid": string;
  "stock.stocklevel": number;
  "stock.timeframe": string;
  "stock.dateback": null;
  "stock.type": string;
}

// Links interface
export interface Links {
  self: string;
}

User avatar
aimeos
Administrator
Posts: 8184
Joined: 01 Jan 1970, 00:00

Re: how to get the complete structure of JSONAPI

Post by aimeos » 10 Sep 2024, 07:59

Please have a look at the field configuration of the manager implementation to see all available fields and their types, e.g. for the attribute manager: https://github.com/aimeos/aimeos-core/b ... #L139-L211
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

mahmoud
Posts: 29
Joined: 27 Mar 2020, 22:01

Re: how to get the complete structure of JSONAPI

Post by mahmoud » 10 Sep 2024, 12:30

thanks.
i have to extract JsonAPI structure from every standard.php file ? for example for catalog:

Code: Select all

private array $searchConfig = array(
		'id' => array(
			'code' => 'catalog.id',
			'internalcode' => 'mcat."id"',
			'label' => 'ID',
			'type' => 'int',
			'public' => false,
		),
		'catalog.siteid' => array(
			'code' => 'catalog.siteid',
			'internalcode' => 'mcat."siteid"',
			'label' => 'Site ID',
			'type' => 'string',
			'public' => false,
		),
		'parentid' => array(
			'code' => 'catalog.parentid',
			'internalcode' => 'mcat."parentid"',
			'label' => 'Parent ID',
			'type' => 'int',
			'public' => false,
		),
		'level' => array(
			'code' => 'catalog.level',
			'internalcode' => 'mcat."level"',
			'label' => 'Tree level',
			'type' => 'int',
			'public' => false,
		),
		'left' => array(
			'code' => 'catalog.left',
			'internalcode' => 'mcat."nleft"',
			'label' => 'Left value',
			'type' => 'int',
			'public' => false,
		),
		'right' => array(
			'code' => 'catalog.right',
			'internalcode' => 'mcat."nright"',
			'label' => 'Right value',
			'type' => 'int',
			'public' => false,
		),
		'label' => array(
			'code' => 'catalog.label',
			'internalcode' => 'mcat."label"',
			'label' => 'Label',
			'type' => 'string',
		),
		'code' => array(
			'code' => 'catalog.code',
			'internalcode' => 'mcat."code"',
			'label' => 'Code',
			'type' => 'string',
		),
		'status' => array(
			'code' => 'catalog.status',
			'internalcode' => 'mcat."status"',
			'label' => 'Status',
			'type' => 'int',
		),
		'catalog.url' => array(
			'code' => 'catalog.url',
			'internalcode' => 'mcat."url"',
			'label' => 'URL segment',
			'type' => 'string',
		),
		'catalog.target' => array(
			'code' => 'catalog.target',
			'internalcode' => 'mcat."target"',
			'label' => 'URL target',
			'type' => 'string',
		),
		'catalog.config' => array(
			'code' => 'catalog.config',
			'internalcode' => 'mcat."config"',
			'label' => 'Config',
			'type' => 'json',
			'public' => false,
		),
		'catalog.ctime' => array(
			'label' => 'Create date/time',
			'code' => 'catalog.ctime',
			'internalcode' => 'mcat."ctime"',
			'type' => 'datetime',
			'public' => false,
		),
		'catalog.mtime' => array(
			'label' => 'Modify date/time',
			'code' => 'catalog.mtime',
			'internalcode' => 'mcat."mtime"',
			'type' => 'datetime',
			'public' => false,
		),
		'catalog.editor' => array(
			'code' => 'catalog.editor',
			'internalcode' => 'mcat."editor"',
			'label' => 'Editor',
			'type' => 'string',
			'public' => false,
		),
		'catalog:has' => array(
			'code' => 'catalog:has()',
			'internalcode' => ':site AND :key AND mcatli."id"',
			'internaldeps' => ['LEFT JOIN "mshop_catalog_list" AS mcatli ON ( mcatli."parentid" = mcat."id" )'],
			'label' => 'Catalog has list item, parameter(<domain>[,<list type>[,<reference ID>)]]',
			'type' => 'null',
			'public' => false,
		),
		'sort:catalog:position' => array(
			'code' => 'sort:catalog:position',
			'internalcode' => 'mcat."nleft"',
			'label' => 'Category position',
			'type' => 'int',
			'public' => false,
		),
	);

and i get that:

Code: Select all

{
  "data": {
    "type": "catalog",
    "id": "catalog.id",
    "attributes": {
      "siteid": "catalog.siteid",
      "parentid": "catalog.parentid",
      "level": "catalog.level",
      "left": "catalog.left",
      "right": "catalog.right",
      "label": "catalog.label",
      "code": "catalog.code",
      "status": "catalog.status",
      "url": "catalog.url",
      "target": "catalog.target",
      "config": "catalog.config",
      "ctime": "catalog.ctime",
      "mtime": "catalog.mtime",
      "editor": "catalog.editor"
    },
    "relationships": {
      "catalog:has": {
        "links": {
          "self": "/catalogs/{id}/relationships/catalog:has",
          "related": "/catalogs/{id}/catalog:has"
        },
        "data": {
          "type": "catalog",
          "id": "catalog-id"
        }
      }
    }
  }
}

User avatar
aimeos
Administrator
Posts: 8184
Joined: 01 Jan 1970, 00:00

Re: how to get the complete structure of JSONAPI

Post by aimeos » 10 Sep 2024, 16:09

The relationship part is always like:

Code: Select all

    "relationships": {
      "catalog": {
        "links": {
          "self": "/jsonapi/catalog/{id}/relationships/catalog",
          "related": "/jsonapi/catalog/{id}/catalog"
        },
        "data": {
          "type": "catalog",
          "id": "catalog-id"
        }
      }
    }
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply