We are new to Here Api,
Our team is working on one transportation project in which we required to get max speed limit of road using vehicle (latitude ,longitude).
From last few days we are trying to figure out which api should we use in HereApi to achieve what we want.
Regarding this documentation of HERE Route Matching 8: https://developer.here.com/documentation/route-matching/api-reference.html
Send please POST request like:
https://routematching.hereapi.com/v8/match/routelinks?apikey=LXX1Axs75efnlFAlgbPxVekPDR0Hz6rTcRHQMT0EvQs&routeMatch=1&mode=fastest;car;traffic:disabled;&attributes=SPEED_LIMITS_FCn(*),LINK_ATTRIBUTE_FCn(*),TRAFFIC_PATTERN_FCn(*),TRUCK_SPEED_LIMITS_FCn(*),SPEED_LIMITS_VAR_FCn(*),SPEED_LIMITS_COND_FCn(*)
With in body:
LATITUDE,LONGITUDE
37.4201866,15.049515
See please attached the Postman collection for test of HERE Rote Match API v8 https://developer.here.com/documentation/route-matching/dev_guide/index.html :
{
"info": {
"_postman_id": "2563b7cc-2d62-4485-bb64-2f9561318aa2",
"name": "RMEspeed_limit",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "1051680"
},
"item": [
{
"name": "speed_limit",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "LATITUDE,LONGITUDE\r\n37.4201866,15.049515"
},
"url": {
"raw": "https://routematching.hereapi.com/v8/match/routelinks?apikey=LXX1Axs75efnlFAlgbPxVekPDR0Hz6rTcRHQMT0EvQs&routeMatch=1&mode=fastest;car;traffic:disabled;&attributes=SPEED_LIMITS_FCn(*),LINK_ATTRIBUTE_FCn(*),TRAFFIC_PATTERN_FCn(*),TRUCK_SPEED_LIMITS_FCn(*),SPEED_LIMITS_VAR_FCn(*),SPEED_LIMITS_COND_FCn(*) ",
"protocol": "https",
"host": [
"routematching",
"hereapi",
"com"
],
"path": [
"v8",
"match",
"routelinks"
],
"query": [
{
"key": "apikey",
"value": "LXX1Axs75efnlFAlgbPxVekPDR0Hz6rTcRHQMT0EvQs"
},
{
"key": "routeMatch",
"value": "1"
},
{
"key": "mode",
"value": "fastest;car;traffic:disabled;"
},
{
"key": "attributes",
"value": "SPEED_LIMITS_FCn(*),LINK_ATTRIBUTE_FCn(*),TRAFFIC_PATTERN_FCn(*),TRUCK_SPEED_LIMITS_FCn(*),SPEED_LIMITS_VAR_FCn(*),SPEED_LIMITS_COND_FCn(*) "
}
]
}
},
"response": []
}
]
}
An apikey and coordinate you specify your own for sure.
About all layers attributes you can see this example: https://demo.support.here.com/pde/maps?url_root=pde.api.here.com
In Python you should use normal POST request using some http libraries developed for Python:
https://www.geeksforgeeks.org/get-post-requests-using-python/
I currently have my application to open a modal when a global shortcut is used. The modal opens and I am presented with 3 options. I was able to get it to push a new modal when any of the options were selected, but now I am stuck on how to open different modals based on the user response. Right now the code does not interpret which was selected, and just that an actionId-0 took place. I guess I am not really sure at the next steps. Do I need to utilize #app.view in order to read the submission payload?
Open on shortcut:
def open_modal(ack, shortcut, client):
# Acknowledge the shortcut request
ack()
# Call the views_open method using the built-in WebClient
client.views_open(
trigger_id=shortcut["trigger_id"],
# A simple view payload for a modal
view={
"title": {
"type": "plain_text",
"text": "#Tech Request"
},
"submit": {
"type": "plain_text",
"text": "Submit"
},
"type": "modal",
"close": {
"type": "plain_text",
"text": "Cancel"
},
"blocks": [
{
"type": "actions",
"elements": [
{
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Select an issue type"
},
"options": [
{
"text": {
"type": "plain_text",
"text": "Account Issues"
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "M1"
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "M2"
},
"value": "value-2"
}
],
"action_id": "actionId-0"
}
]
}
]
}
)
Open when any option is selected:
def update_modal(ack, body, client):
# Acknowledge the button request
ack()
# Call views_update with the built-in client
client.views_update(
# Pass the view_id
view_id=body["view"]["id"],
# String that represents view state to protect against race conditions
hash=body["view"]["hash"],
# View payload with updated blocks
view={
"title": {
"type": "plain_text",
"text": "Account Issue Request"
},
"submit": {
"type": "plain_text",
"text": "Submit"
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is a link to a confluence page"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me",
},
"value": "click_me_123",
"url": "https://google.com",
"action_id": "button-action"
}
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action"
},
"label": {
"type": "plain_text",
"text": "SFDC Contact ID:",
}
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action"
},
"label": {
"type": "plain_text",
"text": "Describe the issue",
}
},
{
"type": "input",
"element": {
"type": "multi_users_select",
"placeholder": {
"type": "plain_text",
"text": "Tag related people",
},
"action_id": "multi_users_select-action"
},
"label": {
"type": "plain_text",
"text": "Tag related people",
}
}
],
"type": "modal"
}
)
This is something that you have to take care of on the backend. I found that the easiest way to do this is to parse the payload received and send back a modal based on that
My bot returns an adaptive card in 1:1 private chat with user, the adaptive card configuration is like this,
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": f"{jiradetail.summary}",
}
]
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Comment",
"card": {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Input.Text",
"id": "comment",
"isMultiline": True,
"placeholder": "Enter your comment"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK",
"data": "**jiraid**"
}
]
}
}
]
}
As you could see, there is a 'comment' textbox and a 'Ok' Action (type Action.Submit, and hidden data->jiraid), the card will be as shown below,
Now on click on this Ok button, I am receiving the activity in ,
on_message_activity, with the user entered value in the commentbox in the field,
turn_context.activity.value
but i couldnt get the hidden data which i mapped to the action button, the below picture shows the inspected value of 'turn_context.activity'.
How can i get the mapped data to this action?
Note: I was also expecting the callback to be, on_teams_messaging_extension_submit_action , but this callback is never called, instead only on_message_activity is called. I assume, its because its an 1:1 conversation and its not invoked via the messageextensions. Any experts please confirm.
Regarding "on_teams_messaging_extension_submit_action" - it's not because it's a 1-1, rather it's because it is NOT a "message extension", it's just a regular Adaptive Card action.
With regards the main issue, about the data not appearing, try to avoid having a direct string value as the "data" payload, and instead try with an object, like this:
...
"data": {"value": "**jiraid**"}
...
Got the answer here,
https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-actions#
For easy reference, this what we are supposed to do,
Adaptive Cards support three action types:
Action.OpenUrl
Action.Submit
Action.ShowCard
In addition to the
actions mentioned above, you can modify the Adaptive Card
Action.Submit payload to support existing Bot Framework actions using
a msteams property in the data object of Action.Submit. The below
sections detail how to use existing Bot Framework actions with
Adaptive Cards.
So the updated payload will be, refer the payload 'msteams' under action->data,
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": f"{jiradetail.summary}",
}
]
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Comment",
"card": {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Input.Text",
"id": "comment",
"isMultiline": True,
"placeholder": "Enter your comment"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK",
"data": {
"msteams": {
"type": "invoke",
"value": {"jiraid":f"{jiradetail.issueid}"}
}
}
]
}
}
]
}
I am running a flask app and using flasgger to generate Swagger Specs as well as a Swagger UI. My API requires the requests to be authenticated using a bearer token. I am able to get the button on the page and set the token. But it is not sent through the requests. I am using OpenAPI 3.0.3. Below is my code:
from flasgger import Swagger
swagger_template = {
'components': {
'securitySchemes': {
'bearerAuth': {
'type': 'http',
'scheme': 'bearer',
'bearerFormat': 'JWT'
}
},
'security': {
'bearerAuth': []
}
}
}
# Register controllers
api = Api(app)
swagger = Swagger(app=app, config={
'headers': [
],
'title': 'Model Design Application API',
'specs': [
{
'endpoint': 'apispec',
'route': '/apispec.json'
}
],
'openapi': '3.0.3'
}, template=swagger_template)
This is the token to be set in the Swagger UI:
This is the UI I get in Swagger:
This is the apispec.json that is generated:
{
"definitions": {
"User": {
"properties": {
"username": {
"default": "Steven Wilson",
"description": "The name of the user",
"type": "string"
}
}
}
},
"info": {
"description": "powered by Flasgger",
"termsOfService": "/tos",
"title": "Model Design Application API",
"version": "0.0.1"
},
"openapi": "3.0.3",
"paths": {
"/profile": {
"get": {
"description": "It works also with swag_from, schemas and spec_dict<br/>",
"responses": {
"200": {
"description": "A single user item",
"schema": {
"$ref": "#/definitions/User"
}
}
},
"summary": "This examples uses FlaskRESTful Resource"
}
}
},
"security": {
"bearerAuth": []
},
"securitySchemes": {
"bearerAuth": {
"bearerFormat": "JWT",
"scheme": "bearer",
"type": "http"
}
}
}
Please advice. Any help is appreciated.
For adding header in Flasgger API, do the following changes:
SWAGGER_TEMPLATE = {"securityDefinitions": {"APIKeyHeader": {"type": "apiKey", "name": "x-access-token", "in": "header"}}}
swagger = Swagger(app, template=SWAGGER_TEMPLATE)
Here, x-access-token is our key name in header. you can change this name according to your requirement.
After this, we need to add this header in our .yml file. Our .yml file will look like this:
summary: "Put your summery here."
description: "Put your description here."
consumes:
- "application/json"
produces:
- "application/json"
security:
- APIKeyHeader: ['x-access-token']
responses:
200:
description: "Success"
Check the working code here
template = {
"swagger": "2.0",
"info": {
"title": XYZ API Docs",
"description": "API Documentation for XYZ Application",
"contact": {
"responsibleOrganization": "",
"responsibleDeveloper": "",
"email": "XYZ#XYZ.com",
"url": "XYZ.com",
},
"termsOfService": "XYZ .com",
"version": "1.0"
},
"basePath": "/api/v1", # base bash for blueprint registration
"schemes": [
"http",
"https"
],
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
"description": "\
JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\""
}
},
"security": [
{
"Bearer": []
}
]
}
swagger_config = {
"headers": [
],
"specs": [
{
"endpoint": 'apispec',
"route": '/apispec.json',
"rule_filter": lambda rule: True, # all in
"model_filter": lambda tag: True, # all in
}
],
"static_url_path": "/flasgger_static",
"swagger_ui": True,
"specs_route": "/api/v1/apispec"
}
I'm building a Django Rest Framework and want to test the API with coreapi library. I can create an object using coreapi programmatically inside a python script but in command line, I can't create the same object and when I list coreapi endpoints I get a list with only endpoints for reading and listing, even when I add a valid credential.
My Schema:
{
"_type": "document",
"_meta": {
"url": "http://127.0.0.1:8000/api/schema/",
"title": "NEP API"
},
"experiments": {
"list": {
"_type": "link",
"url": "/api/experiments/",
"action": "get",
"fields": [
{
"name": "page",
"location": "query",
"schema": {
"_type": "integer",
"title": "Page",
"description": "A page number within the paginated result set."
}
}
]
},
"create": {
"_type": "link",
"url": "/api/experiments/",
"action": "post",
"encoding": "application/json",
"fields": [
{
"name": "title",
"required": true,
"location": "form",
"schema": {
"_type": "string",
"title": "Title",
"description": ""
}
},
{
"name": "description",
"required": true,
"location": "form",
"schema": {
"_type": "string",
"title": "Description",
"description": ""
}
},
{
"name": "data_acquisition_done",
"location": "form",
"schema": {
"_type": "boolean",
"title": "Data acquisition done",
"description": ""
}
},
{
"name": "nes_id",
"required": true,
"location": "form",
"schema": {
"_type": "integer",
"title": "Nes id",
"description": ""
}
},
{
"name": "ethics_committee_file",
"location": "form",
"schema": {
"_type": "string",
"title": "Project file approved by the ethics committee",
"description": ""
}
},
{
"name": "sent_date",
"required": true,
"location": "form",
"schema": {
"_type": "string",
"title": "Sent date",
"description": ""
}
}
]
},
"read": {
"_type": "link",
"url": "/api/experiments/{nes_id}/",
"action": "get",
"fields": [
{
"name": "nes_id",
"required": true,
"location": "path",
"schema": {
"_type": "string",
"title": "",
"description": ""
}
}
]
},
"update": {
"_type": "link",
"url": "/api/experiments/{nes_id}/",
"action": "put",
"encoding": "application/json",
"fields": [
{
"name": "nes_id",
"required": true,
"location": "path",
"schema": {
"_type": "string",
"title": "",
"description": ""
}
},
{
"name": "title",
"required": true,
"location": "form",
"schema": {
"_type": "string",
"title": "Title",
"description": ""
}
},
{
"name": "description",
"required": true,
"location": "form",
"schema": {
"_type": "string",
"title": "Description",
"description": ""
}
},
{
"name": "data_acquisition_done",
"location": "form",
"schema": {
"_type": "boolean",
"title": "Data acquisition done",
"description": ""
}
},
{
"name": "nes_id",
"required": true,
"location": "form",
"schema": {
"_type": "integer",
"title": "Nes id",
"description": ""
}
},
{
"name": "ethics_committee_file",
"location": "form",
"schema": {
"_type": "string",
"title": "Project file approved by the ethics committee",
"description": ""
}
},
{
"name": "sent_date",
"required": true,
"location": "form",
"schema": {
"_type": "string",
"title": "Sent date",
"description": ""
}
}
]
},
"partial_update": {
"_type": "link",
"url": "/api/experiments/{nes_id}/",
"action": "patch",
"encoding": "application/json",
"fields": [
{
"name": "nes_id",
"required": true,
"location": "path",
"schema": {
"_type": "string",
"title": "",
"description": ""
}
},
{
"name": "title",
"location": "form",
"schema": {
"_type": "string",
"title": "Title",
"description": ""
}
},
{
"name": "description",
"location": "form",
"schema": {
"_type": "string",
"title": "Description",
"description": ""
}
},
{
"name": "data_acquisition_done",
"location": "form",
"schema": {
"_type": "boolean",
"title": "Data acquisition done",
"description": ""
}
},
{
"name": "nes_id",
"location": "form",
"schema": {
"_type": "integer",
"title": "Nes id",
"description": ""
}
},
{
"name": "ethics_committee_file",
"location": "form",
"schema": {
"_type": "string",
"title": "Project file approved by the ethics committee",
"description": ""
}
},
{
"name": "sent_date",
"location": "form",
"schema": {
"_type": "string",
"title": "Sent date",
"description": ""
}
}
]
},
"delete": {
"_type": "link",
"url": "/api/experiments/{nes_id}/",
"action": "delete",
"fields": [
{
"name": "nes_id",
"required": true,
"location": "path",
"schema": {
"_type": "string",
"title": "",
"description": ""
}
}
]
}
},
}
As you see, all methods are listed here and I cant create an experiment object by using coreapi programmatically inside a script, for example, running (inside a python script):
client.action(
schema, ['experiments', 'create'],
params={'title': 'An experimet', 'description': 'A description',
'nes_id': 2, 'sent_date': '2017-01-01'}
)
But when using coreapi in command line I can't create same object.
Getting schema:
$ coreapi get http://127.0.0.1:8000/api/schema
display the and points when not logged:
<NEP API "http://127.0.0.1:8000/api/schema/">
experiments: {
groups: {
list(experiment_nes_id, [page])
}
studies: {
list(experiment_nes_id, [page])
}
list([page])
read(nes_id)
}
groups: {
list([page])
}
protocol_components: {
list([page])
read(nes_id)
}
studies: {
list([page])
}
Then, I add my credentials:
$ coreapi credentials add 127.0.0.1 "lab1":"nep-lab1" --auth basic
Reload the schema:
$ coreapi reload
and the result is again
<NEP API "http://127.0.0.1:8000/api/schema/">
experiments: {
groups: {
list(experiment_nes_id, [page])
}
studies: {
list(experiment_nes_id, [page])
}
list([page])
read(nes_id)
}
groups: {
list([page])
}
protocol_components: {
list([page])
read(nes_id)
}
studies: {
list([page])
}
Now, I expect that the endpoints would appear including create, update etc. but no.
And when I try to create an experiment object running:
$ coreapi action experiments create --param nes_id=5 --param title="A" --param description="B" --param sent_date="2001-01-01"
I get, as expected:
Index ['experiments']['create'] did not reference a link. Key 'create' was not found.
url conf:
I am using Default Router to generate REST uri's:
router.register(r'experiments', api.ExperimentViewSet,
base_name='api_experiments')
router = DefaultRouter()
and including in url conf:
url(r'^', include(router.urls)),
Sorry by the long text. I wanted to include as much as information I thought was necessary.
Had the same issue when working on tutorial (part 7) at official Django Rest Framework site.
Found one solution:
manually add header Authorization to requests using coreapi headers add HEADER VALUE, where VALUE is the string of characters, which is generated when you add credentials of user. For some reason my coreapi didn't add this header automatically to request as I found with --debug option.
Here is example:
Before credentials are added I can see only safe methods:
$ coreapi get http://127.0.0.1:8000/schema/
<Pastebin API "http://127.0.0.1:8000/schema/">
snippets: {
list([page])
read(id)
highlight(id)
}
users: {
list([page])
read(id)
}
Then I add credentials of superuser admin:
coreapi credentials add 127.0.0.1 "admin:password" --auth basic
Added credentials
127.0.0.1 "Basic BlahBlahBlah="
It looks like coreapi successfully add credentials, but when I try to reload schema, I still get the same methods:
$ coreapi reload
<Pastebin API "http://127.0.0.1:8000/schema/">
snippets: {
list([page])
read(id)
highlight(id)
}
users: {
list([page])
read(id)
}
I found that there is no Authorization header in GET request with value Basic BlahBlahBlah=:
$ coreapi reload --debug
> GET /schema/ HTTP/1.1
> Accept-Encoding: gzip, deflate
> Connection: keep-alive
> Accept: application/coreapi+json, application/vnd.coreapi+json, */*
> Host: 127.0.0.1
> User-Agent: coreapi
Well, let's try to add this header to our request manually:
$ coreapi headers add "Authorization" "Basic BlahBlahBlah="
Added header
Authorization: Basic BlahBlahBlah=
Try again to get schema:
$ coreapi get http://127.0.0.1:8000/schema/
<Pastebin API "http://127.0.0.1:8000/schema/">
snippets: {
list([page])
create(code, [title], [linenos], [language], [style])
read(id)
update(id, code, [title], [linenos], [language], [style])
partial_update(id, [title], [code], [linenos], [language], [style])
delete(id)
highlight(id)
}
users: {
list([page])
read(id)
}
Now I see all other methods available to authorized users only. If I execute previous command with --debug option, there will be the header:
> GET /schema/ HTTP/1.1
> Accept-Encoding: gzip, deflate
> Connection: keep-alive
> Accept: application/coreapi+json, application/vnd.coreapi+json, */*
> Authorization: Basic BlahBlahBlah=
> Host: 127.0.0.1
> User-Agent: coreapi
For example, now I can create code snippet:
$ coreapi action snippets create --param title="Example" --param code="print('hello, world')"
{
"url": "http://127.0.0.1:8000/snippets/6/",
"id": 6,
"highlight": "http://127.0.0.1:8000/snippets/6/highlight/",
"owner": "admin",
"title": "Example",
"code": "print('hello, world')",
"linenos": false,
"language": "python",
"style": "friendly"
}
But still there is the question Why doesn't coreapi add Authorization header automatically?
I found the exact same issue on Django Rest Framework tutorial, so it is still an issue with these versions:
$ pip list
...
coreapi (2.3.3)
coreapi-cli (1.0.6)
...
The issue documented here: https://github.com/core-api/coreapi-cli/issues/19. Relevant excerpt:
coreapi-cli is using the deprecated credentials argument for HTTPTransport instead of auth. As you can see from the code here, coreapi 2.3.1 is ingesting that deprecated argument, but then doing nothing with it. This is why this library won't send auth headers anymore.
I can confirm that adding the header fixed it for me. In summary:
coreapi clear
coreapi credentials add 127.0.0.1 admin:password --auth basic
coreapi credentials show
coreapi headers add "Authorization" "Basic ...=="
coreapi get http://127.0.0.1:8000/schema/ --debug
Copy-paste the string from "credentials show" command into "headers add" command.
This is a known bug with version 2.3.x. of coreapi-cli. A fix is coming soon, see:
Issue tracked on Github
The work around is as per Sergey Dulevich's previous answer.
Just wanted to mention that i do not see these issue's when using the python client directly (when providing Basic Auth credentials).
from coreapi import Client
client = Client(auth=HTTPBasicAuth('user', 'pass'))
document = client.get(args.endpoint)
data = client.action(document, ['catalog', 'create', ], params={
'start': '2018-08-30T10:00:00Z',
'end': '2018-08-30T11:00:00Z',
'filename': 'my-filename',
})
This also happened to me after authenticating on basic-auth with:
$ coreapi credentials add 127.0.0.1 <user>:'<pass>' --auth basic
Now you will find the REST un-SAFE methods are listed, using: coreapi action snippets list - check for those methods:
list([page])
create(code, [title], [linenos], [language], [style])
read(id)
update(id, code, [title], [linenos], [language], [style])
partial_update(id, [title], [code], [linenos], [language], [style])
delete(id)
read_0(id, format)
read_1(id, format)
update_0(id, format, code, [title], [linenos], [language], [style])
partial_update_0(id, format, [title], [code], [linenos], [language], [style])
delete_0(id, format)
Then if I tried to create a resource such as:
$ coreapi action snippets create --param title="Example" --param code="print('hello, world from the CLI')"
it would fail with "Index ['snippets']['create'] did not reference a link. Key 'create' was not found."
I was able to solve it by reading again the schema after the auth step:
$ coreapi get http://127.0.0.1:8008/schema/
This must act like a refresh of the schema and it then allows to create the resource using the exact same code from above.
Try it and see if it works for you as well.