Samples using API. User Guide

Similar documents
API Documentation. Release Version 1 Beta

Version 1.2. ASAM CS Single Sign-On

Using OAuth 2.0 to Access ionbiz APIs

HappyFox API Technical Reference

Quriiri HTTP MT API. Quriiri HTTP MT API v , doc version This document describes the Quriiri HTTP MT API version 1 (v1).

Leveraging the Security of AWS's Own APIs for Your App. Brian Wagner Solutions Architect Serverless Web Day June 23, 2016

ExtraHop Rest API Guide

Authorization and Authentication

Asema IoT Central Notification API 1.0. English

OAuth at Interactive Brokers

ENERGY MANAGEMENT INFORMATION SYSTEM. EMIS Web Service for Sensor Readings. Issue

Tenable.io Container Security REST API. Last Revised: June 08, 2017

argcomplete Documentation Andrey Kislyuk

URL Signing and Validation

Enable API Access... 3 Set up API Access... 4

argcomplete Documentation

Using the YANG Development Kit (YDK) with Cisco IOS XE

Version Event Protect Platform RESTfull API call

Table of Contents. Developer Manual...1

Version Event Protect Platform RESTfull API call

Standard HTTP format (application/x-www-form-urlencoded)

Weights and Biases Documentation

The Merit Palk API allows 3rd party developers to expand and build on the Merit Palk platform.

IOCs. Reference: Domains

Beyond Virtual Machines: Tapping into the AWS Universe from FileMaker

Welcome to. Python 2. Session #5. Michael Purcaro, Chris MacKay, Nick Hathaway, and the GSBS Bootstrappers February 2014

Documentation to use the Elia Solar Forecasting web services

PERFORMANCE HORIZON PUBLISHER API INTRODUCTION

Oracle Fusion Middleware. API Gateway OAuth User Guide 11g Release 2 ( )

Report API v1.0 Splio Customer Platform

SAS Event Stream Processing 4.2: Security

URL Signing and Validation

Public Appointment API. Calendar A

Integrate Mimecast Secure Gateway. EventTracker v8.x and above

Controller/server communication

ENERGY MANAGEMENT INFORMATION SYSTEM. EMIS Web Service for Remote Readings and Bills. Issue

API Gateway. Version 7.5.1

Standard HTTP format (application/x-www-form-urlencoded)

Version Date Description Author First version Nate. send_sms request Added DELIVERED. status in Send Sms.

ClickToCall SkypeTest Documentation

The system has several front-end content discovery options. Here are examples of their interfaces (see more on our site at

NIELSEN API PORTAL USER REGISTRATION GUIDE

MxVision WeatherSentry Web Services REST Programming Guide

PROCE55 Mobile: Web API App. Web API.

Archer Documentation. Release 0.1. Praekelt Dev

1WorldSync Content1 Web Services

urllib2 extensible library for opening URLs

API Wrapper Documentation

Pemrograman Jaringan Web Client Access PTIIK

IPConfigure Embedded LPR API

All requests must be authenticated using the login and password you use to access your account.

JSON POST WITH PHP IN ANGULARJS

05/11/2018 graph-stats.py 1 #!/usr/bin/env python

Controller/server communication

flask-jwt-simple Documentation

API Developer s Guide

WeChat Adobe Campaign Integration - User Guide

SimSun "zh" = 0pt plus 1pt

Errors Message Bad Authentication Data Code 215 User_timeline

Composer Help. Web Request Common Block

Moxie Notifications Documentation

Ninox API. Ninox API Page 1 of 15. Ninox Version Document version 1.0.0

ExtraHop 7.3 ExtraHop Trace REST API Guide

SMS Outbound. HTTP interface - v1.1

Region wise sales reporting collation

BaasBox. Open Source Backend as a Service. Otto Hylli

STATS API: AN INTRODUCTION

Advanced API Security

APPENDIX B - Python Scripts

CS 155 Project 2. Overview & Part A

C U B I T S. API DOCUMENTATION Version 1.8

Python Call Graph. Release Gerald Kaszuba

ACCUZIP EDDM UI REST API CALLS. 100% Cloud Based EDDM List Creation. Abstract EDDM UI to select Carrier Route Boundaries throughout the United States

ArubaOS-Switch_REST Documentation

Alloy Navigator API USER S GUIDE. Integration with External Systems. Product Version: 7.0 Document Revision: 1.0 Date: November 30, 2015

Escher Documentation. Release Emarsys

Messaging Service REST API Specification V2.3.2 Last Modified: 07.October, 2016

Integrating with ClearPass HTTP APIs

ARTIO SMS Services HTTP API Documentation

address view... 3 URL... 3 Method... 3 URL Params... 3 Required... 3 Optional... 3 Data Params... 4 Success Response... 4 Error Response...

Pay with Amazon Express Integration Guide

HTTP Authentication API

NETSUITE INTEGRATION. Guide to Setting up Token-Based Authentication in NetSuite

XML API Developer-Documentation Version 2.01

HTTP API Specification V2.7

Using Redis for data processing in a incident response environment.

The production version of your service API must be served over HTTPS.

I was given the following web application: and the instruction could be found on the first page.

PAS for OpenEdge Support for JWT and OAuth Samples -

Using Arcpy.mapping and ArcGIS Server Admin API to Automate Services

Documentation to use the Elia Wind Forecasting web services

Lab 5: Working with REST APIs

RSA NetWitness Logs. Salesforce. Event Source Log Configuration Guide. Last Modified: Wednesday, February 14, 2018

Data Web Service - Client Guide

CIS192 Python Programming

Ad-ID COMPLETE EXTERNAL ACCESS (CEA) SPECIFICATION

string signature = CreateSignature(secretKey, messagerepresentation); // hwce6v2ka0kkb0gbbik0gsw5qacs3+vj+m+wn/8k9ee=

API Application Programmers Interface

httplib2 Release 0.4

REST. Lecture BigData Analytics. Julian M. Kunkel. University of Hamburg / German Climate Computing Center (DKRZ)

Transcription:

Samples using API User Guide

1 Table of Contents 1 Table of Contents... 2 2 Python sample... 4 2.1 callapi.py file configuration...7 3 Bash sample... 9 4 JavaScript sample...11

This article describes 3 samples of using API in the following cases: 3

2 Python sample There are 4 mandatory parameters for this script: apikey apisecret datefrom dateto -k (- - apikey) : API Key of the domain (Administration Credentials API Key) -s (- - apisecret) : API secret of the domain (Administration Credentials API Secret) -f (- -datefrom) : query start date as "YYYY-MM-DD HH:MM:SS" -t (- -date to) : query end date as "YYYY-MM-DD HH:MM:SS" Apart from these, at least one of these parameters should also be included: query idsearch -q (- - query) : LINQ query -id (- - idsearch) : query ID (Query Info Get ID) This is an example of a query run on the web application: 4

And this is a request with Python script using the query (q):./callapi.py -k '2y0D9HPK128PpsHURcDr9Vz6xtAGeVYz' -s 'ytbgi7yw4dah52tmn9txdrjfftfphsey' -f '2016-03-15 00:00:00' -t '2016-03-15 12:00:00' -q 'from siem.logtrust.web.activity where method = "GET" select lu("cursoimagenio1", "nombrespruebas", "nombre", username) as Nombre group every 0 by Nombre, username, userid, domain' This is a request with Python script, with the query ID (id): 5

./callapi.py -k '2y0D9HPK128PpsHURcDr9Vz6xtAGeVYz' -s 'ytbgi7yw4dah52tmn9txdrjfftfphsey' -f '2016-03-15 00:00:00 -t '2016-03-15 12:00:00' -id '69242b69-fe79-4542-beac-de0718a13774'...and the corresponding answer: { "status": 0, "msg": "valid request", "object": [{ "username": "rmoya@logtrust.com 1 ", "Nombre": "Ricardo", "domain": "cursoimagenio1", "userid": "c722465f-28eb-4d70-b282-0c238f195ce1" }, {...}, {...} ], "success": true} 1 http://logtrust.com 6

2.1 callapi.py file configuration #!/usr/bin/env python # -*- coding: utf8 # # Example of how to query logtrust search API: #./callapi.py -k "apikey" -s "apisecret" -f "2016-01-01 00:00:00" -t "2016-01-02 00:00:00" -q "query" # import hmac import hashlib import datetime import time import urllib import httplib2 import json import argparse import sys import re # Parameters parser = argparse.argumentparser() parser.add_argument("-k", "--apikey", required=true, help="administración > Credenciales > Api Key") parser.add_argument("-s", "--apisecret", required=true, help="administración > Credenciales > Api Secret") parser.add_argument("-f", "--datefrom", required=true, help="must have the following format YYYY-MM-DD HH:MM:SS") parser.add_argument("-t", "--dateto", required=true, help="must have the following format YYYY-MM-DD HH:MM:SS") parser.add_argument("-q", "--query", required=false, help="from my.app.nivel1.nivel2 select *") parser.add_argument("-id", "--idsearch", required=false, help="query Info > Get Id") args = parser.parse_args() DATEREGEX = '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$' URL = 'https://api.logtrust.com/lt-api/storedsearchaction.json' API_KEY = args.apikey API_SECRET = args.apisecret # Query or idsearch if not args.idsearch and not args.query: print 'ERROR: BOTH PARAMETERS ARE MISSING' sys.exit() elif args.idsearch and args.query: print 'ERROR: BOTH PARAMETERS ARE PRESENT' sys.exit() elif args.idsearch and not args.query: ID_SEARCH = args.idsearch QUERY = None else: 7

ID_SEARCH = None QUERY = args.query # Date patter = re.compile(dateregex) if patter.match(args.datefrom): date = datetime.datetime.strptime(args.datefrom, "%Y-%m-%d %H:%M:%S") DATE_FROM = str(int(time.mktime(date.timetuple()) * 1000)) else: print "ERROR: THE START DATE (datefrom) MUST HAVE THE FOLLOWING FORMAT YYYY-MM-DD HH:MM:SS" sys.exit() if patter.match(args.dateto): date = datetime.datetime.strptime(args.dateto, "%Y-%m-%d %H:%M:%S") DATE_TO = str(int(time.mktime(date.timetuple()) * 1000)) else: print "ERROR: THE END DATE (dateto) MUST HAVE THE FOLLOWING FORMAT YYYY-MM-DD HH:MM:SS" sys.exit() # Timestamp TSTAMP = str(int(time.mktime(datetime.datetime.now().timetuple()) * 1000)) # Message if ID_SEARCH is None: MSG = API_KEY + DATE_FROM + DATE_TO + QUERY + TSTAMP elif QUERY is None: MSG = API_KEY + DATE_FROM + DATE_TO + ID_SEARCH + TSTAMP # Signature sign = hmac.new(api_secret, MSG, hashlib.sha256) # Request req = httplib2.http() if ID_SEARCH is None: params = dict(apikey=api_key, query=query, datefrom=date_from, dateto=date_to, timestamp=tstamp, sign=sign.hexdigest()) elif QUERY is None: params = dict(apikey=api_key, idsearch=id_search, datefrom=date_from, dateto=date_to, timestamp=tstamp, sign=sign.hexdigest()) headers = {'content-type': 'application/x-www-form-urlencoded'} resp, jsoncontent = req.request(url, "POST", urllib.urlencode(params), headers) content = json.dumps(json.loads(jsoncontent)) print content 8

3 Bash sample See below a Bash sample using API. 9

#!/bin/bash #Fix attributes URL = 'https://api.logtrust.com/lt-api/storedsearchaction.streamjson' CONTENT_TYPE='Content-Type:application/x-www-form-urlencoded; charset=utf-8' #Domain Api Key and Secret apikey='xfrtw05vsag26nbtpar49ucyf54xxqhñ' apisecret='abq30qipc0g7gtda8trs7t53wxzelcv6' #Query or idquery #example query='from my.app.test.test group every 30m every 0 select count() as count' #queryid =idquery #Period to Query datefrom=`date -d "2017-03-29 00:00:00.000" +%s000` dateto=`date -d "2017-03-30 00:00:00.000" +%s000` #Current Timestamp timestamp=`date +%s000` #Sign the REST call _stringsign="$apikey$datefrom$dateto$query$timestamp" sign=`echo $_stringsign tr -d '\n' openssl dgst -sha256 -hmac "$apisecret"` sign=`echo $sign awk -F '= ' '{print $2}'` #Data to send with Post petition data="apikey=$apikey&datefrom=$datefrom&dateto=$dateto&query=$query&ti mestamp=$timestamp&sign=$sign" #Data to send with Post petition with QueryId #data="apikey=$apikey&datefrom=$datefrom&dateto=$dateto&query=$queryid &timestamp=$timestamp&sign=$sign" #HTTP Request curl -H "$CONTENT TYPE" -d "$data" "$URL" 10

4 JavaScript sample See below a JavaScript sampe using API: http://logtrust-static.s3.amazonaws.com/downloads/signaturechecker.html 11