让决策更智能
新一代智能数据分析平台

如何通过api获取卡片数据

观小远发表于:2021年05月11日 16:46:04更新于:2021年05月11日 16:49:20

背景:

部分场景下需要在外部场景中接入观远卡片数据,可以使用该方式获取卡片数据(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

Name

Location

类型

含义

是否必填

备注

cardId

Path

String

卡片ID


X-Auth-Token

Header

String

登录用的Token

Token需要通过sign-in接口获取

dynamicParams

Body

JSON

动态参数



filter

Body

JSON

过滤器


指定过滤条件,包括name,filterType,filterValue

name:过滤的列名(注意填原始名字,不要填卡片里的别名);

filterType:过滤类型;

filterValue:过滤值

limit

Body

Int

获取的数据条数



offset

Body

Int

数据的起始位置



view

Body

String

数据获取方式

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",
                "#3FB27E",
                "#9BCC7E",
                "#F35352",
                "#FF9193",
                "#9D61C2",
                "#CAAED8",
                "#8FA500",
                "#BFD000"
            ]
        },
        "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)的形式组织。

    您需要登录后才可以回复