Zend Apigility Doctrine 404 Entity Not Found Error - zend-framework

I'm having a bit of an issue here with grabbing a value off of my entity, I think it may be related to the reflection or hydration w/in Doctrine, but I'm not sure... All I know is if I run:
$product = $entity->getRepository('Products')->findOneBy(array('product_id' => $site->product_id));
If I return $product here, I get the collection:
{
"product_id": 1,
"title": "Product",
}
But if I try to return $product->title I get
{
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Not Found",
"status": 404,
"detail": "Entity not found."
}
Any thoughts?

A coworker helped me through this one... apparently Apigility hydrates the collection, but requires everything sent back as an array. So the object gets serialized, but the integer gets errored. So...
I changed $product->title
to [$product->title]

Related

POST request to JIRA REST API to create issue of type Minutes

my $create_issue_json = '{"fields": { "project": { "key": "ABC" }, "summary": "summary for version 1", "description": "Creating an issue via REST API", "issuetype": { "name": "Minutes" }}}';
$tx1 = $jira_ua->post($url2 => json => decode_json($create_issue_json));
my $res1 = $tx1->res->body;
I try to create a jira issue of type Minutes but POST expects some fields which are not available in the issue of type Minutes. The below is the response.
{"errorMessages":["Brands: Brands is required.","Detection: Detection is required."],"errors":{"versions":"Affects Version/s is required.","components":"Component/s is required."}}
I also tried to fetch the schema using createMeta api but don't find any useful info. The below is the response from createmeta.
{"maxResults":50,"startAt":0,"total":3,"isLast":true,"values":[
{
"self":"https://some_url.com/rest/api/2/issuetype/1",
"id":"1",
"description":"A problem which impairs or prevents the functions of the product.",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=25683&avatarType=issuetype",
"name":"Bug",
"subtask":false},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/12",
"id":"12",
"description":"An issue type to document minutes of meetings, telecons and the like",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=28180&avatarType=issuetype",
"name":"Minutes",
"subtask":false
},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/23",
"id":"23",
"description":"Used to split an existing issue of type \"Bug\"",
"iconUrl":"https://some_url.com:8443/images/icons/cmts_SubBug.gif",
"name":"Sub Bug",
"subtask":true
}
]
}
It looks like there Jira Admin has added these as manadatory fields for all the issuetypes which I came to know after speaking with him. He has now individual configuration for different issue types and am able to create minutes.

SuiteCrm Rest API: JSON Body attributes throws error when calling POST or PUT

I'm using postman in order to call SuiteCRM REST API.
I tried to call this endpoint
PATCH http://{{suitecrm-url}}/Api/V8/module
and i've added this payload to the body (Content-Type: Application/Json):
{
"data": {
"type": "Accounts",
"id": "3a3ae651-d509-2508-7dc4-5be2e51cc96b",
"attributes": {
"name": "name with space"
}
}
}
When the request is executed SuiteCRM gives this response:
{
"errors": {
"status": 400,
"title": null,
"detail": "The option \"attributes\" with value array is invalid."
}
}
I found out that the problem was the whitespace in the value: when i tried to use the value "namewithspace", it worked.
Anyone has any idea how to solve this problem ?
Thanks in advance
I found out this issue on github that resolved my problem:
https://github.com/salesagility/SuiteCRM/issues/6452
In short to make it work i had to modify the file in
/Api/V8/Params/Options/Fields.php
and replace this line
const REGEX_FIELD_PATTERN = '/[^\w-,]/';
with
const REGEX_FIELD_PATTERN = '/[^\w-,\s\]/';
The person mentioned in github:
this is just for temporary fix and not upgrade safe

FindById gives me "code": "MODEL_NOT_FOUND" - loopback 3

I have been facing this weird issue lately that on a given model when I try to fetch an item by Id it throws an error even though this item exists in the db.
{ "error": {
"statusCode": 404,
"name": "Error",
"message": "Unknown \"BidSample\" id \"5afc396af6584c07cf1b729c\".",
"code": "MODEL_NOT_FOUND" } }
I am using mongo database and loopback 3.
It might be that in the database it has been soft deleted.

Can't post node that requires a pre assigned value with services api

I have setup a content type with a subject field that has pre assigned values in a dropdown field.
I am using the services api to post new content from a polymer app.
When I POST to the api I send the field structure and value in json but get and error.
"406 (Not Acceptable : An illegal choice has been detected. Please contact the site administrator.)"
Even though the object I am sending matches one of the required values in the field.
Do I need to prefix the value with something? I assume I'm posting to the right place to get that response but don't know why it would accept anything other than the string value.
Here is what I sent to the api which is picked up by my Charles proxy.
{
"node": {
"type": "case",
"title": "my case",
"language": "und",
"field_subject": {
"und": {
"0": {
"value": "subject1"
}
}
},
"body": {
"und": {
"0": {
"value": "my details of subject"
}
}
}
}
}
And here is an example of what I have setup in my Drupal field
subject1| first
subject2| second
subject3| third
subject4| forth
For anyone else with the same problem, this subject is poorly documented, but the answer is simple, my subject did not need the value key despite devel suggesting thats how it would be formatted.
"field_subject": {
"und": [
"subject1"
]
}
I could also shorten my code with "und" being an array.

datatype of complextype entity is null when returning an array of complex types

We have created a complextype field "carriers" which is an array of Carrier objects. See below metadata
"dataProperties": [
{
"name": "carriers",
"complexTypeName":"Carrier#Test",
"isScalar":false
}]
The Carrier entity is defined as below:
{
"shortName": "Carrier",
"namespace": "Test",
"isComplexType": true,
"dataProperties": [
{
"name": "Testing",
"isScalar":true,
"dataType": "String"
}
]
}
We are trying to return an array of complextype in breeze from a REST service call. We get an error in breeze.debug.js in the method proto._updateTargetFromRaw. The error is because the datatype is null.
Any idea how to fix this issue?
I'm guessing the problem is in your "complexTypeName". You wrote "Carrier#Test" when I think you meant to write "Carrier:#Test". The ":#" combination separates the "short name" from the namespace; you omitted the colon.
Hope that's the explanation.