SugarCRM API - Filter POST - Related Module Fields - sugarcrm

I'm trying to retrieve, using REST API, a list of records and one of its related module fields. Let's assume Accounts and Opportunities.
So, API Documentation (in the GET Filter) talks about defining related module in the fields parameter:
According to the same documentation, it would provide a result similiar to:
That's exactly what I need, but I'm trying to achieve this using the POST method. So, following the same path, I'm sending (using Postman):
PS: I tried all combinations of double quotes. Escaped, not escaped, with or without it, all of them give me the same result, that is:
The message is in pt-BR but it means "One of your request parameters is wrong". The HTTP status code is 422 - Unprocessable Entity.
What am I doing wrong? I tried everything and just don't know how to make it work. Looks like the documentation talks about something that simply don't work or doesn't exist.

Okay, so after some research, it seems that Postman uses something similar to Chrome and it isn't really possible to send GET requests with the values in the body. However, you can...
Encode the values into the URL and send it through Postman:
https://yoursite.com/rest/v10/Accounts?filter%5B0%5D%5Bopportunities.date_modified%5D%5B%24gte%5D%3D2016-02-29T00%3A00%3A00&fields=cpf_c,opportunities&max_num=10
Use curl:
curl -X GET -H Host:yoursite.com -H OAuth-Token:d49c8fd4-0ae0-d9fb-7ab8-5846e5a3fa86 -H Cache-Control:no-cache -d '{"filter":[{"opportunities.date_modified":{"$gte":"2016-02-29T00:00:00"}}],"fields":["cpf_c","opportunities"],"max_num":"10"}' https://yoursite.com/rest/v10/Accounts
Or build the HTTP request directly, and include the body:
GET https://yoursite.com/rest/v10/Accounts HTTP/1.1
Host: yoursite.com
OAuth-Token:d49c8fd4-0ae0-d9fb-7ab8-5846e5a3fa86
Cache-Control:no-cache
{"filter":[{"opportunities.date_modified":{"$gte":"2016-02-29T00:00:00"}}],"fields":["cpf_c","opportunities"],"max_num":"10"}
To test this, I created 3 Accounts, 2 of which had an Opportunity linked. The response was this when I used "name" instead of your "cpf_c" field:
{
"next_offset": -1,
"records": [{
"id": "64417139-459c-852f-3a73-5846ed1245c2",
"name": "another account with opp",
"date_modified": "2016-12-06T16:54:29+00:00",
"opportunities": {
"next_offset": -1,
"records": [{
"id": "32d1d320-c560-92d6-7def-5846eda786da",
"date_modified": "2016-12-06T16:55:06+00:00",
"_acl": {
"fields": {}
},
"_module": "Opportunities"
}]
},
"_acl": {
"fields": {}
},
"_module": "Accounts"
}, {
"id": "48dc47dd-bbf1-816d-b0ac-5846e6dd9e21",
"name": "test with opp",
"date_modified": "2016-12-06T16:23:33+00:00",
"opportunities": {
"next_offset": -1,
"records": [{
"id": "79c3bf6f-6c2b-7945-09f7-5846e6c610d7",
"date_modified": "2016-12-06T16:24:20+00:00",
"_acl": {
"fields": {}
},
"_module": "Opportunities"
}]
},
"_acl": {
"fields": {}
},
"_module": "Accounts"
}]
}
Hope this helps.

Related

Using REST API to create alerting rule in Kibana fails on 400 "Invalid action groups: default"

I have ELK cloud v. 7.13.2 and trying to create alert rule with slack action via REST API. This is my curl invocation:
curl -u ****** -s -H 'kbn-xsrf: true' -H 'Content-Type: application/json' https://***********.westeurope.azure.elastic-cloud.com:9243/api/alerting/rule -X POST -d #src/rules/cpu_utilization.json
I am expecting that new rule is created, but unfortunately I am getting following error:
{
"statusCode": 400,
"error": "Bad Request",
"message": "Invalid action groups: default"
}
The contents of src/rules/cpu_utilization.json are:
{
"params": {
"nodeType": "host",
"criteria": [
{
"comparator": ">",
"timeSize": 1,
"metric": "cpu",
"threshold": [
80
],
"timeUnit": "m"
}
],
"sourceId": "default"
},
"consumer": "alerts",
"schedule": {
"interval": "1m"
},
"tags": [],
"name": "CPU2",
"throttle": "1000d",
"enabled": true,
"rule_type_id": "metrics.alert.inventory.threshold",
"notify_when": "onThrottleInterval",
"actions": [
{
"group": "default",
"id": "fce4c27f-d22a-4209-858c-253a06511c1b",
"params": {
"message": "{{alertName}} - {{context.group}} is in a state of {{context.alertState}}\n\nReason:\n{{context.reason}}"
}
}
]
}
Documentation says clearly:
Properties of the action objects:
group
(Required, string) Grouping actions is recommended for escalations for different types of alerts. If you don’t need this, set this value to default.
Is this a bug in ELK or I am doing something wrong? I am able to use API for other purposes, like listing rules, deleting rules etc. I am also capable of creating a rule without an action, but this doen`t seem to be too useful...
OKAY, I got an answer from ELK support. Apparently, you can use another endpoint to list all rule types GET /api/alerting/rule_types. Then you need to find your type and lookup property default_action_group_id - it will hold the correct value. Eg. in the above example it was:
"default_action_group_id": "metrics.inventory_threshold.fired"

How do I use Marketo REST API with Postman?

I'm having a hard time trying to figure out how to properly use the Marketo REST API using Postman for testing purpose.
So far I can Authenticate and get my access_token,
but when I try to create a folder... (properly authenticated)
endpoint: [POST] /rest/asset/v1/folders.json
body:
{
"description": "Test Folder",
"name": "Test",
"parent": {
"id": 1,
"type": "Folder"
}
}
I get:
{
"success": false,
"errors": [
{
"message": "name cannot be null.",
"code": "701"
},
{
"message": "parent cannot be null",
"code": "701"
}
],
"requestId": "408a#1720c00a893",
"warnings": []
}
I don't know what I'm doing wrong.
See an example in the Marketo API documentation
Create/Update folder request should be an application/x-www-form-urlencoded not application/json
So in Postman, you have to post a form with three parameters:
parent={"id":416,"type":"Folder"}
name=Test 10 - deverly
description=This is a test
For the parent parameter you should specify a specific json-like text, which is a usual format for folderId
For generic folders (not programs) you can provide just integer id, without JSON structure, this is not recommended but can be used for manual API tests

Creating a domain in Plesk's REST API

So, experimenting with Plesk's REST API (available as of version 17.8) for a project at work, and I'm starting to get a feel for it. I've been trying to experiment with adding a domain, but it's been giving me errors when I have to specify the hosting type.
The request body itself is as follows:
{
"name":"example.com",
"hosting_type":"virtual",
"description":"Description goes here"
}
This gets the following cryptic response:
{
"code": 1014,
"message": "htype\/vrt_hst is specified but there is no hosting\/vrt_hst"
}
Per the documentation provided at /api/v2/swagger.yml, any of the following values should be allowed: virtual, standard_forwarding, frame_forwarding, none
No matter what I put in, however, I get a variant of the response above (htype\/{type} is specified but there is no hosting\/{type}).
At this point I'm kind of stuck; I'm not sure what to check, and any references when I try to look up the error code go to references on Plesk's XML API instead. What's the missing link here needed to get the request to work?
It looks like system user is not specified - hosting_settings. Try to add domain with full json request. Here is example:
{
"name": "example.com",
"description": "My website",
"hosting_type": "virtual",
"hosting_settings": {
"ftp_login": "test_login",
"ftp_password": "test_pwd"
},
"base_domain": {
"id": 7,
"name": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"parent_domain": {
"id": 7,
"name": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"owner_client": {
"id": 7,
"login": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1",
"external_id": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"ipv4": [
"212.192.122.46"
],
"ipv6": [
"2002:5bcc:18fd:c:123:123:123:123"
],
"plan": {
"name": "Unlimited"
}
}
Examples for REST API https://app.swaggerhub.com/apis/plesk/api/v2#/Domains/post_domains

Jira Rest API: Requesting issue(s) of a specific user in one or more projects (Beginner)

For testing and practice purposes I want to create a specific request in Jira by using its REST api:
I want to list all issues from a specific user in one or more specific projects.
I tried it with SOAP UI but I was not able to create or get my results with easy GET-HTTP requests (I don't know how to combine more values and parameter together). The other way would be to use a script language but here I don't know what to use.
The documentation is somewhat confusing for a beginner like me and I would like to know how combine different values and paramter and how to start in an easy way.
Try to use advance rest client for chrome browsers to make your Rest requests.
The examples below (from official documentation) are for Curl usage but its simple to pass them to advance rest client. Dont forget the authentication.
Link to advance rest client
Example of create issue:
Request
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/
Data
{
"fields": {
"project":
{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
Response
{
"id":"39000",
"key":"TEST-101",
"self":"http://localhost:8090/rest/api/2/issue/39000"
}
Example of making a query issue:
Request:
curl -D- -u fred:fred -X GET -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/search?jql=assignee=fred
Response:
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 50,
"total": 6,
"issues": [
{
"expand": "html",
"id": "10230",
"self": "http://kelpie9:8081/rest/api/2/issue/BULK-62",
"key": "BULK-62",
"fields": {
"summary": "testing",
"timetracking": null,
"issuetype": {
"self": "http://kelpie9:8081/rest/api/2/issuetype/5",
"id": "5",
"description": "The sub-task of the issue",
"iconUrl": "http://kelpie9:8081/images/icons/issue_subtask.gif",
"name": "Sub-task",
"subtask": true
},
},
"customfield_10071": null
},
"transitions": "http://kelpie9:8081/rest/api/2/issue/BULK-62/transitions",
},
{
"expand": "html",
"id": "10004",
"self": "http://kelpie9:8081/rest/api/2/issue/BULK-47",
"key": "BULK-47",
"fields": {
"summary": "Cheese v1 2.0 issue",
"timetracking": null,
"issuetype": {
"self": "http://kelpie9:8081/rest/api/2/issuetype/3",
"id": "3",
"description": "A task that needs to be done.",
"iconUrl": "http://kelpie9:8081/images/icons/task.gif",
"name": "Task",
"subtask": false
},
"transitions": "http://kelpie9:8081/rest/api/2/issue/BULK-47/transitions",
}
]
}

GET Values from a custom field via JIRA REST API

I would like to GET all drop down options for a custom field. For system fields, I use the following URI:
http://localhost:8080/rest/api/2/project/XXXX/components
(for components, versons, etc. Basically system fields), so I tried the following for a custom field
http://localhost:8080/rest/api/2/project/XXXX/customfield_10000
and got a 404 error. I'm not sure what I'm doing wrong as I've been googling for the past 19 hours. The best I search result I got was the following documentation: JIRA Developers Documentation
Please assist, I'm not sure What I'm missing
You can get that information either from the createmeta or editmeta REST resources.
Use editmeta if you want to retrieve the available options when editing a specific issue. E.g.
GET /rest/api/2/issue/TEST-123/editmeta
Use createmeta when you want to retrieve the options for a project in combination with an issue type. E.g.
GET /rest/api/2/issue/createmeta?projectKeys=MYPROJ&issuetypeNames=Bug&expand=projects.issuetypes.fields
The customfields with options will be returned like this:
"customfield_12345": {
"schema": {
"type": "string",
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:select",
"customId": 12345
},
"name": "MySelectList",
"allowedValues": [
{
"self": "http://jira.url/rest/api/2/customFieldOption/14387",
"value": "Green",
"id": "14387"
},
{
"self": "http://jira.url/rest/api/2/customFieldOption/14384",
"value": "Blue",
"id": "14384"
}
]
}