#generalbots - I would like to integrate my bot with an external API, but i don't know the process of define URL, Headers and Params and setup the return Json.
I didn't try anything yet. I am currently trying to develop this process.
To define HTTP headers in a GET keyword call use the following:
SET HTTP USERNAME = "YOUR_USERNAME"
SET HTTP PASSWORD = "YOUR_PASSWORD"
With these headers defined, it is possible to call the authenticated GET, after asking for a numeric code in the conversation:
TALK "Please, what is your code?"
HEAR code as NUMBER
data = GET "https://api.domain.com/lists/customers?code=" + code
TALK "Hello, " + data.name + "."
Please, refer to the BotBook repository for more information: https://github.com/GeneralBots/BotBook/blob/master/book/chapter-05-gbdialog-reference.md#using-post-data.
Related
I'm having some trouble getting a GET Action with body to work in BluePrism (using web api service).
It seems that when I try to include an Action that sends a GET with body when I reach that stage this error gets thrown:
Internal : Unexpected error Cannot send a content-body with this verb-type.
What I've tried:
Using a different verb-type / passing parameters in the query instead of the body, unfortunately i don't have control over the endpoint i'm trying to reach so this didnt work as it only accepts a GET containing data in the body
Using BluePrism HTTP Utility to send the call, this has the same problem as the Web API Service
Compiling the body via code instead of using a template
I haven't been able to find anyone that made it work in BluePrism and there doesn't seem to be much documentation on this issue in BluePrism so any help would be appreciated.
Thanks!
.NET's WebRequest class that Blue Prism uses under the hood to conduct
these requests will not allow you to send a request body with any GET
request. There is no (documented) way to overcome this limitation.
While other related answers on Stack
Overflow correctly state
that there exists no such prohibition on including request bodies with
GET requests per RFC
9110§9.3.1, it is
very unusual for a production-grade service to require that the request
itself include anything in the request body. It's also possible that
intermediaries like HTTP proxies may strip or otherwise mangle the request
body in transit anyway.
There is no out-of-the-box way to force the .NET Framework (which Blue
Prism uses) to send GET requests with a request body. If you're able,
you can install
WinHttpHandler
and implement it as a drop-in replacement for HTTPRequest (this SO
thread will help).
Because this type of solution requires the install of a new library, it's
important to consider the caveats of doing so:
Blue Prism's support for external DLLs is unstable at best, and there's
no guarantee it will even import correctly to begin with. Vendor support
for this type of setup is, anecdotally, limited to nonexistent (and
rightfully so, IMO).
If you're able to successfully implement the functionality described
with WinHttpHandler, you'll need to install it on every Blue Prism
developer's machine and runtime resource in all your environments
(development/SIT/UAT/production). For some organizations, strict IT
security posture makes this rather impractical or outright infeasible.
I managed to get it working using a code block containing C# code and using Reflection, here is a my GET method:
public string GetWithBodyAndAuth(string uri, string data, string token, out int statusCode)
{
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Headers.Add("Authorization", "Basic " + token);
request.ContentType = "application/json; charset=utf-8";
request.Method = "GET";
request.Accept = "application/json";
var type = request.GetType();
var currentMethod = type.GetProperty("CurrentMethod", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(request);
var methodType = currentMethod.GetType();
methodType.GetField("ContentBodyNotAllowed", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(currentMethod, false);
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(data);
}
var response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
statusCode = ((int)response.StatusCode);
return reader.ReadToEnd();
}
It's a bit of a hack and can't say if it'll be supported in the future, but for BluePrism 6.9 this allows you to send GET requests containing a body.
It has the advantage of not requiring any external DLLs, this is the import list:
I was looking at the Github API and it allows you to fetch all repository invites through an API endpoint (see https://developer.github.com/v3/repos/invitations/#list-invitations-for-a-repository). This works fine like this:
from requests.auth import HTTPBasicAuth
import requests
login = 'xxx'
password = 'yyy'
url = 'https://api.github.com/user/repository_invitations'
repository_invites = requests.get(
url, auth=HTTPBasicAuth(login, password)).json()
print('response: ' + str(repository_invites))
I can then get out each request its url like this:
for repository_invite in repository_invites:
print('url: ' + repository_invite.get('url'))
Which gives something back like:
url: https://api.github.com/user/repository_invitations/123456789
Github also mentions that you can accept an invite at https://developer.github.com/v3/repos/invitations/#accept-a-repository-invitation which mentions
PATCH /user/repository_invitations/:invitation_id
What I don't get is how I can tell Github how to accept it though. This endpoint seems to be used for both deleting and accepting an invitation. Github talks about PATCH at https://developer.github.com/v3/#http-verbs which mentions you can use either a POST or send a PATCH request, however not how. So the question is, how do I know what I should send in the PATCH call? I tried this for example:
result = requests.patch(repository_invite.get('url'), json.dumps({'accept': True}))
print('result: ' + str(result.json()))
Which gives back:
result: {'message': 'Invalid request.\n\n"accept" is not a permitted key.', 'documentation_url': 'https://developer.github.com/v3'}
In order to call the API endpoint you will need to have authentication with your Github user and you need to send a Patch call (which can take data/headers if you would need them). Here's a working sample:
for repository_invite in repository_invites:
repository_id = repository_invite.get('id')
accept_invite = requests.patch('https://api.github.com/user/repository_invitations/'+ str(repository_id),
data={}, headers={},
auth=HTTPBasicAuth(github_username, github_password))
Without the authentication the Patch call will give back a 404 response code because it is only accessible behind a login for obvious safety purpose. If you call the endpoint user/repository_invitations/ followed by the ID Github will automatically accept the invitation.
I have recently been working with API's but I am stuck on one thing and it's been holding me back for a few days.
I am trying to work with Privacy's API and I do not understand the Authentication/Authorization process. When I enter the url in a browser I get the error "message": "Please provide API key in Authorization header", even when I use the correct format of Authorization. I also get an error when I make a request in Python. The format I'm using for the url is https://api.privacy.com/v1/card "Authorization: api-key:".
If someone could explain how to work this or simply give an example of how I would make a request through Python3. The API information is in the link below.
Thank you in advance.
https://developer.privacy.com/docs
This is the code I am using in Python. After I run this I receive a 401 status code.
import requests
headers={'Authorization': 'api-key:200e6036-6894-xxxx-xxxx-xxxx'}
url = 'https://api.privacy.com/v1/card'
r = requests.get(url)
print("Status code:", r.status_code)
You need to add the authentication header to the get call. It isn't enough to include it in a header variable. You need to provide those headers to requests
import requests
response = requests.get('https://api.privacy.com/v1/card', headers={'Authorization': 'api-key 65a9566c-XXXXXXXXXXXX'})
print(response.json())
Hi in one of my response i am getting this xml
<root><err>0</err><errDesc></errDesc><state>3</state><p1>{C4739B96-E12A-429B-9A03-0B5B5F814D3C}</p1><p2>{1C33A258-D50E-4D44-8309-83665FC6073E}</p2><p5>1</p5><p6>QdjXQJy0SVnamdLJqMMHz/Cxtu8Dbw21q5caSX9uwoBlZDvBfHJx1R7QfknQ+f564YfmnEyRnJ1TJ5DF+ZOK2g==</p6><p7></p7><p8>{00000000-0000-0000-0000-000000000000}</p8><p9>0</p9><returnmessage></returnmessage></root>
I need to extract id between p6 tags and pass it as a cookie in subsequent request as CPSession.
How to achieve this in C# Web Performance Testing.
Any help would be hugely appreciated.
I am trying to write a web test request plugin and in its prerequest method i am trying to write a method to achieve this with following code
CookieContainer gaCookies = new CookieContainer(); Uri target = new Uri("http://susday4446.corp.ncr.com:8091/core/ui/uiBrowser.aspx");
> gaCookies.Add(new Cookie("CPSession", "QdjXQJy0SVnamdLJqMMHz/Cxtu8Dbw21q5caSX9uwoBlZDvBfHJx1R7QfknQ+f564YfmnEyRnJ1TJ5DF+ZOK2g==");
> { Domain = target.Host }
But this is not able to add cookie in this request.
Right now all i am trying to do is passing CPSession as a cookie its value i have hardcoded.
I have a requirement (flexible) to use oauth2. (existing architecture/code)
I have a need to do some text manipulation of subscriber's email headers.
Solutions I've tried.
I've tried to download the sample code for java and it correctly connects to gmail's imap servers. It however responds with oath_version=1 and is expecting a password. I've tried to massage the code to change the params as other api's like their Contacts api oauth2 without success.
Question:
(multipart)
Api is down:http://code.google.com/googleapps/domain/email_migration/developers_guide_java.html any reference online would be ideal (it has been down for at least half a week since last week Wed). If you wondered - yes I did post on their forums before asking here for the updated link.
Is there a way to: a) make oauth2 request and b) Any (minimal) code exaples I can look at would be great.
Thanks in advance for reading this post.
Here is a working, Ruby example of fetching email from Google using the OAuth2 protocol:
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false)
imap.authenticate('XOAUTH2', 'example#gmail.com', 'oauth2_access_token_goes_here')
imap.select('INBOX')
imap.search(['ALL']).each do |message_id|
msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
mail = Mail.read_from_string msg
puts mail.subject
puts mail.text_part.body.to_s
puts mail.html_part.body.to_s
end
Note: This example uses ruby mail gem and gmail_xoauth gem, so you will need those installed for this code sample to work. I am also using the omniauth and omniauth-google-oauth2 gems to handle logging the user in and using the access token.