跳到主要内容
版本:5.9.0

如何通过api获取卡片数据

背景

部分场景下需要在外部场景中接入观远卡片数据,可以使用该方式获取卡片数据(json格式),之后对明文数据进行解析和加工,可得到需要的数据信息。

获取方法

1、用户名密码方式登录获取合法Token

home_url示例:https://app.guandata.com

URL    $home_url/public-api/sign-in

method    POST

Parameters

NameLocation类型含义是否必填备注
Content-TypeHeaderString内容类型
domainBodyString域名在观远系统中的域名,非网址的域名
emailBodyString登录的邮箱如果开启了账号登录模式则该参数不传,传loginId和对应的内容
passwordBodyString密码原始密码经过Base64编码后的字符串

Header 示例

{     
  "Content-Type": "application/json; charset=utf-8" 
}

POST Body 示例

{
  "domain":"demo",
  "email":"123@456.com",
  "password":"my_password_base64_encoded"
}
  • 注意:参数中password需要base64 encode。

Response

{
  "result":"ok",
  "response":
  {
    "token":"guanyuan token", /* 该token在后面调用其他接口时使用 */
    "expireAt":"2021-01-01 00:00:00.00"
  }
}

2、获取卡片数据

URL  

$home_url/public-api/card/{cardId}/data

method

POST

Parameters

NameLocation类型含义是否必填备注
cardIdPathString卡片ID
X-Auth-TokenHeaderString登录用的TokenToken需要通过sign-in接口获取
dynamicParamsBodyJSON动态参数
filterBodyJSON过滤器指定过滤条件,包括name,filterType,filterValuename:过滤的列名(注意填原始名字,不要填卡片里的别名);filterType:过滤类型;filterValue:过滤值
limitBodyInt获取的数据条数
offsetBodyInt数据的起始位置
viewBodyString数据获取方式GRAPH:图形形式GRID:表格形式

POST Body 示例

{
    "dynamicParams": [],
    "filters": [{
        "name": "gender",
        "filterType": "IN",
        "filterValue": ["F"]
        }],
    "limit": 200,
    "offset": 0,
    "view": "GRAPH"
}
{    
    "dynamicParams": [],
    "filters": [{
        "name": "gender",
        "filterType": "IN",
        "filterValue": ["F"]
        }],
    "limit": 200,
    "offset": 0,
    "view": "GRID"
}

其中,filterType(过滤器)支持以下形式:

GT (>), GE (>=), LT (<), LE(<=), EQ (==), NE (!=),

IN (IN LIST), NI (NOT IN LIST),

STARTSWITH, NOT_STARTSWITH,

ENDSWITH, NOT_ENDSWITH,

CONTAINS, NOT_CONTAINS,

IS_NULL, NOT_NULL

Response示例

{
    "chartMain": {
        "meta": {
            "categories": [
                {
                    "name": "大类代码",
                    "displayName": "大类代码",
                    "parentFdName": null,
                    "fdId": "d1a63a97399464c7bb704ea9",
                    "fdType": "LONG",
                    "granularity": null
                }
            ],
            "series": [
                {
                    "cols": [
                        {
                            "value": null
                        }
                    ],
                    "metric": {
                        "name": "单价",
                        "fdType": "DOUBLE",
                        "idx": 0
                    }
                }
            ],
            "direction": "vertical",
            "splitSetting": null,
            "dataLabels": {
                "metric": {
                    "showSeries": false,
                    "showCategory": false,
                    "showNumber": true,
                    "fontSize": 12,
                    "separator": "comma",
                    "position": "outside"
                },
                "metricAdditional": {
                    "showSeries": false,
                    "showCategory": false,
                    "showNumber": false,
                    "fontSize": 12,
                    "separator": "comma",
                    "position": "outside"
                }
            },
            "axes": {
                "categoryAxis": {
                    "showTitle": false,
                    "title": null,
                    "autoStep": true,
                    "step": "",
                    "distance": "",
                    "visible": true
                },
                "mainAxis": {
                    "tickInterval": null,
                    "max": "",
                    "unit": null,
                    "tickPosition": null,
                    "autoTickInterval": true,
                    "visible": true,
                    "min": "",
                    "distance": "",
                    "autoExtremes": true,
                    "showGridLine": true,
                    "title": null,
                    "showTitle": false,
                    "minorTickPosition": null
                },
                "navigator": {
                    "showNavigator": false
                }
            },
            "auxiliaryLine": null,
            "theme": null,
            "colors": [
                "#0781C3",
                "#FF7500",
                "#83BFF4",
                "#FFB86C",
            ]
        },
        "colorAxis": {
            "title": {
                "text": "大类代码"
            },
            "format": null
        },
        "limitInfo": {
            "hasMoreData": false,
            "dataLimit": 5000,
            "hasMoreCol": false,
            "colLimit": 5000
        },
        "categories": [
            "1",
            "2"
        ],
        "series": [
            {
                "name": "单价",
                "data": [
                    {
                        "y": 60.269,
                        "colorBy": 1
                    },
                    {
                        "y": 43.03,
                        "colorBy": 2
                    }
                ],
                "format": null
            }
        ]
    },
    "view": "GRAPH",
    "rawDataNotChanged": false,
    "chartType": "BASIC_COLUMN",
    "cardType": "CHART"
}

此结果按照图形的展示要求组织,横轴数据为 categories,纵轴数据为 series。

{
    "chartMain": {
        "row": {
            "meta": [
                {
                    "fdId": "d1a63a97399464c7bb704ea9",
                    "title": "大类代码",
                    "originTitle": "大类代码",
                    "fdType": "LONG",
                    "metaType": "DIM",
                    "parentFdName": null,
                    "granularity": null,
                    "headerFormat": null
                }
            ],
            "values": [
                [
                    {
                        "titleType": "LONG",
                        "granularity": null,
                        "title": "1"
                    }
                ],
                [
                    {
                        "titleType": "LONG",
                        "granularity": null,
                        "title": "2"
                    }
                ]
            ],
            "dimThreshold": [
                null
            ],
            "showAsPicture": [
                null
            ]
        },
        "column": {
            "meta": [
                {
                    "title": "度量",
                    "metaType": "METRIC",
                    "headerFormat": null
                }
            ],
            "values": [
                [
                    {
                        "title": "单价",
                        "type": "metric",
                        "fmt_idx": 0,
                        "fdType": "DOUBLE",
                        "headerFormat": null
                    }
                ]
            ],
            "dimThreshold": [],
            "showAsPicture": [],
            "format": [
                null,
                null
            ],
            "threshold": [
                null,
                null
            ]
        },
        "data": [
            [
                {
                    "v": 60.269
                }
            ],
            [
                {
                    "v": 43.03
                }
            ]
        ],
        "meta": {
            "dataLabels": {
                "metric": {
                    "showSeries": false,
                    "showCategory": false,
                    "showNumber": true,
                    "fontSize": 12,
                    "separator": "comma",
                    "position": "outside"
                },
                "metricAdditional": {
                    "showSeries": false,
                    "showCategory": false,
                    "showNumber": false,
                    "fontSize": 12,
                    "separator": "comma",
                    "position": "outside"
                }
            },
            "axes": {
                "categoryAxis": {
                    "showTitle": false,
                    "title": null,
                    "autoStep": true,
                    "step": "",
                    "distance": "",
                    "visible": true
                },
                "mainAxis": {
                    "tickInterval": null,
                    "max": "",
                    "unit": null,
                    "tickPosition": null,
                    "autoTickInterval": true,
                    "visible": true,
                    "min": "",
                    "distance": "",
                    "autoExtremes": true,
                    "showGridLine": true,
                    "title": null,
                    "showTitle": false,
                    "minorTickPosition": null
                },
                "navigator": {
                    "showNavigator": false
                }
            }
        },
        "offset": 0,
        "limit": 200,
        "hasMoreData": false,
        "count": 2,
        "limitInfo": {
            "hasMoreData": false,
            "dataLimit": 20000,
            "hasMoreCol": false,
            "colLimit": 100
        }
    },
    "view": "GRID",
    "rawDataNotChanged": false,
    "chartType": "BASIC_COLUMN",
    "cardType": "CHART"
}

获取的数据形式按照行(row)、列(column)表头以及数据块(data)的形式组织。