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

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

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.

VSTS Variable Group API for updating a variable?

Is there a API call (maybe a PUT) available to update variables in a variable group?
I tried a PUT to
https://<my>.visualstudio.com/<project>/_apis/distributedtask/variablegroups
with JSON like
{"variables": {"somevariable":{"value":"12"}}}
But I get an error
The requested resource does not support http method 'PUT'.
Thanks
Variable group can be updated by REST API. Details as below:
PUT https://account.visualstudio.com/DefaultCollection/{project}/_apis/distributedtask/variablegroups/{variableGroupId}?api-version=4.1-preview
application/json
{
"variables": {
"var1": {
"value": "new value"
},
"var2": {
"value": "new value"
}
},
"type": "Vsts",
"name": "variable group name",
"description": "Updated variable group"
}
After much trial and error with this I found an excellent tutorial here - This worked for me:
Updating a VSTS variable group from the command line
Thanks Daniel Stocker!

AcrCloud Not able to upload audio file

Getting below error even we are passing title in request body
{
"name": "Unprocessable entity",
"message": "Lack field:title",
"code": 0,
"status": 422
}
Any Help will be appreciable.
You need to fill up the title field. Which is required.
please refer to this example code
https://github.com/acrcloud/webapi_example/tree/master/RESTful%20service

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.

Facebook Credits Invalid State Transition Error

I am using Github sample code for the Facebook Credits (callback.php and index.php) but its giving me the below error.. anybody have any solution???
"Order::update_order called with invalid state transition:3 -> 0"
Thanks..
Hard to answer without seeing the code you're using, but the response you send should look like this:
{
"method": "payments_status_update",
"content": {
"order_id": ORDER_ID,
"status": "settled"
}
}
ORDER_ID should be replaced by the order id sent from fB with the request.
There were incorrect examples out there that showed:
{
"method": "payments_status_update",
"content": [{
"order_id": ORDER_ID,
"status": "settled"
}]
}
but the second one doesn't work. Check to make sure you're not sending content as an array.