Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Invalid value provided (invalid IRI?) Error testing POST endpoint #1099

Open
msechi opened this issue Apr 11, 2019 · 8 comments
Open
Labels

Comments

@msechi
Copy link

msechi commented Apr 11, 2019

I have a Product entity (that implements an interface I made - AuthoredUsedEntity), related to another User entity with a relation manyToOne. AuthoredUsedEntity is used to populate the user field in Product with the current logged in User.

when I make an api call to /api/products (I use postman) passing a json like this:

{
"name": "my product",
"price": 10
}

this works and a new record is created with the correct userID. The problem is with unit tests. I make a call like this:

$headers = [
    'HTTP_AUTHORIZATION' => 'Bearer ' . $token,
    'CONTENT_TYPE' => 'application/ld+json',
    'HTTP_ACCEPT' => 'application/ld+json'
];
$postData = [
'name' => 'my product',
'price' => 10
];
$client = $this->makeClient();
$client->request('POST', '/api/products', [], [], $headers, json_encode($postData));

and I get this error: Invalid value provided (invalid IRI?)

am I doing anything wrong? For tests I am using phpunit and Liip.

thanks
M

@msechi
Copy link
Author

msechi commented Apr 12, 2019

any idea anyone?

@Arkowsky
Copy link

Try use just application/json as CONTENT_TYPE and HTTP_ACCEPT in your tests in this case.

@msechi
Copy link
Author

msechi commented Apr 15, 2019

@Arkowsky yes I tried already, same result.
thanks

@Arkowsky
Copy link

I think you have to setId after you create object and this is the issue. Your identifier is empty and after create is called normalizer to show your results so you need to have id set.

@msechi
Copy link
Author

msechi commented Apr 16, 2019

@Arkowsky as mentioned it works using POSTMAN. The issue must be something different given that it is failing when testing only, and only with POST/PUT calls.

@coolfarmer
Copy link

@Arkowsky as mentioned it works using POSTMAN. The issue must be something different given that it is failing when testing only, and only with POST/PUT calls.

Same problem here, have you found a solution?

@jonytrifulca
Copy link

Take a look on this line

$client->request('POST', '/api/products', [], [], $headers, json_encode($postData));

try to don´t make a json_encode() , only pass the $postData like an array.

$response = $client->request( 'POST', $url, [ 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json' ], 'json' => $postData ]);

@silviodeligios
Copy link

I have the same problem :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants