Symfony API platform - nelze přidat relační záznam - An error occurred - Invalid IRI
Dobrý den,
použivám Symfony API platform a když chci přidat relační záznam, tak dostávám chybu:
exception":"[object] (Symfony\\Component\\Serializer\\Exception\\UnexpectedValueException(code: 0): Invalid IRI \"879\". at
Nedaří se zkrátka odeslat vazební (relační) subdata na existujici data pres vazebni ID 879
JSON request:
------------------------------------------------------------------
array
data => "879" (3)
identifier => "Km" (2)
value => 55.0
Response ERROR
------------------------------------------------------------------
{"@context":"\/api\/contexts\/Error","@type":"hydra:Error","hydra:title":"An error occurred","hydra:description":"Invalid IRI \u0022879\u0022.","trace":
API očekává dle http
------------------------------------------------------------------
POST
/api/subdatas
Creates a subdata resource.
Parameters
Try it out
No parameters
Request body
application/ld+json
The new subdata resource
Example Value
Schema
{
"data": "string",
"identifier": "string",
"value": "string",
}
Entita subdata
------------------------------------------------------------------
* @ApiResource(
* collectionOperations={"get"={"normalization_context"={"groups"="data:list"}},"post"},
* itemOperations={"get"={"normalization_context"={"groups"="data:item"}},"delete","put"},
* order={"date"="DESC", "type"="ASC"},
* paginationEnabled=true,
* attributes={
* "pagination_items_per_page"=10
* }
* )
.............
/**
* @ORM\ManyToOne(targetEntity=data::class, inversedBy="subdata")
* @ORM\JoinColumn(nullable=false)
*
* @Groups({"subdata:list", "subdata:item"})
*/
private $data;
Zdrojová data sestavuji takto:
------------------------------------------------------------------
$data = [
"data" => $slug,
"identifier" => 'Km',
"value" => $r->km,
];
V logu /var/log/dev.log je:
------------------------------------------------------------------
[2021-04-13T10:39:35.332291+02:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Serializer\Exception\UnexpectedValueException: "Invalid IRI "879"." at /var/www/symfony/webapp5/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php line 431 {"exception":"[object] (Symfony\\Component\\Serializer\\Exception\\UnexpectedValueException(code: 0): Invalid IRI \"879\". at /var/www/symfony/webapp5/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php:431)\n[previous exception] [object] (ApiPlatform\\Core\\Exception\\InvalidArgumentException(code: 0): No route matches \"879\". at /var/www/symfony/webapp5/vendor/api-platform/core/src/Bridge/Symfony/Routing/IriConverter.php:77)\n[previous exception] [object] (Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0): No routes found for \"/879/\". at /var/www/symfony/webapp5/vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php:70)"} []
DODATEK: dalsi chyba
------------------------------------------------------------------
The type of the value attribute must be string, integer given
JSON: {"@context":"\/api\/contexts\/Error","@type":"hydra:Error","hydra:title":"An error occurred","hydra:description":"The type of the \u0022value\u0022 attribute must be \u0022string\u0022, \u0022integer\u0022 given.","trace":
Ahoj,
nikde jsem se to nedočetl, až na jednom blogu:
Nestačí pouze uvést vazební (relační) id, ale je třeba se v API platform odkát na celou API cestu k relačnímu záznamu ve tvaru '/api/streams/555, takze data musí vypadat takto:
$data = [
"stream" => '/api/streams/'. $slug,
"identifier" => 'Km',
"value" => (string) $r->km,
"suser" => 2,
];
A dotatkovou chybu The type of the value attribute must be string, integer given jsem vyřešil takto:
použivám Symfony API platform a když chci přidat relační záznam, tak dostávám chybu:
exception":"[object] (Symfony\\Component\\Serializer\\Exception\\UnexpectedValueException(code: 0): Invalid IRI \"879\". at
Nedaří se zkrátka odeslat vazební (relační) subdata na existujici data pres vazebni ID 879
JSON request:
------------------------------------------------------------------
array
data => "879" (3)
identifier => "Km" (2)
value => 55.0
Response ERROR
------------------------------------------------------------------
{"@context":"\/api\/contexts\/Error","@type":"hydra:Error","hydra:title":"An error occurred","hydra:description":"Invalid IRI \u0022879\u0022.","trace":
API očekává dle http
------------------------------------------------------------------
POST
/api/subdatas
Creates a subdata resource.
Parameters
Try it out
No parameters
Request body
application/ld+json
The new subdata resource
Example Value
Schema
{
"data": "string",
"identifier": "string",
"value": "string",
}
Entita subdata
------------------------------------------------------------------
* @ApiResource(
* collectionOperations={"get"={"normalization_context"={"groups"="data:list"}},"post"},
* itemOperations={"get"={"normalization_context"={"groups"="data:item"}},"delete","put"},
* order={"date"="DESC", "type"="ASC"},
* paginationEnabled=true,
* attributes={
* "pagination_items_per_page"=10
* }
* )
.............
/**
* @ORM\ManyToOne(targetEntity=data::class, inversedBy="subdata")
* @ORM\JoinColumn(nullable=false)
*
* @Groups({"subdata:list", "subdata:item"})
*/
private $data;
Zdrojová data sestavuji takto:
------------------------------------------------------------------
$data = [
"data" => $slug,
"identifier" => 'Km',
"value" => $r->km,
];
V logu /var/log/dev.log je:
------------------------------------------------------------------
[2021-04-13T10:39:35.332291+02:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Serializer\Exception\UnexpectedValueException: "Invalid IRI "879"." at /var/www/symfony/webapp5/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php line 431 {"exception":"[object] (Symfony\\Component\\Serializer\\Exception\\UnexpectedValueException(code: 0): Invalid IRI \"879\". at /var/www/symfony/webapp5/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php:431)\n[previous exception] [object] (ApiPlatform\\Core\\Exception\\InvalidArgumentException(code: 0): No route matches \"879\". at /var/www/symfony/webapp5/vendor/api-platform/core/src/Bridge/Symfony/Routing/IriConverter.php:77)\n[previous exception] [object] (Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0): No routes found for \"/879/\". at /var/www/symfony/webapp5/vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php:70)"} []
DODATEK: dalsi chyba
------------------------------------------------------------------
The type of the value attribute must be string, integer given
JSON: {"@context":"\/api\/contexts\/Error","@type":"hydra:Error","hydra:title":"An error occurred","hydra:description":"The type of the \u0022value\u0022 attribute must be \u0022string\u0022, \u0022integer\u0022 given.","trace":
ODPOVĚĎ
Ahoj,
nikde jsem se to nedočetl, až na jednom blogu:
Nestačí pouze uvést vazební (relační) id, ale je třeba se v API platform odkát na celou API cestu k relačnímu záznamu ve tvaru '/api/streams/555, takze data musí vypadat takto:
$data = [
"stream" => '/api/streams/'. $slug,
"identifier" => 'Km',
"value" => (string) $r->km,
"suser" => 2,
];
A dotatkovou chybu The type of the value attribute must be string, integer given jsem vyřešil takto:
"value" => (string) $r->km,
Show english version