Good Evening,
I'm attempting to connect Alteryx to the Open People Search API. Here is the curl:
curl -X POST "https://api.openpeoplesearch.com/api/v1/Consumer/PhoneSearch" -H "accept: text/plain" -H "Authorization: Bearer ****************************************" -H "Content-Type: application/json" -d "{\"phoneNumber\":\"123456789\"}"
I'm trying to use the text tool + the download tool to get this started. I tried to feed the data to the download like such but I get a bad request error. Any ideas?
URL https://api.openpeoplesearch.com/api/v1/Consumer/PhoneSearch
Header 1 accept: text/plain
Header 2 Authorization: Bearer **************************************** The * symbols were replaced with a valid token.
Header 3 Content-Type: application/json
Payload {\"phoneNumber\":\"123456789\"}
Error
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Header</h2>...
Any ideas on what I could adjust?
Solved! Go to Solution.
The OpenPeople API example is based on the curl command. Nothing wrong with curl, actually it is very powerful, the problem is with the tutorial explaining API's in Alteryx which is not based on curl as it uses HTTP end-points; that's the first hurdle, strip the curl command from the OpenPeople example.
You should watch this 25 minutes video API's in Alteryx created by the Kiwi Ryan Edwards, the video is fantastic, it is based on the The Guardian Open Platform and within the video you get all the instructions to download "news", the Guardian is a very popular news source at this corner of the world.
Out of the video I created an Alteryx workflow consuming the Guardian API, following the video suggestion I also installed Postman on my laptop; actually Postman is a great tool if you are implementing APIs in Alteryx, so I strongly suggest you install it in your resources.
OpenPeople API:
You probable already know this, anyhow, this is a one-off first step, getting our OpenPeople token, we will need it in Alteryx
Problem:
Postman:
The body is initially imported like: {firstName:Roberto,middleName:,lastName:Aguirre,city:Miami,state:FL}
We have to amend it, to include the quotes as shown in the image:
{"firstName":"Roberto","middleName":"","lastName":"Aguirre","city":"Miami","state":"FL"}
WARNING:
You don't have unlimited tests, OpenPeople stop servicing data returning the message: "HTTP/1.1 402 Payment Required"
Alteryx:
Basic tab: no changes
Header: Add the keys: accept, Authorization and Content-Type; copy them from "Postman"
Payload tab (this is actually the API call body); set the HTTP Action to POST and paste the body as shown (copy the body from Postman)
NOTES/COMMENTS:
hth
Arnaldo
Wow! Thank you so much for the super detailed info and working workflow! The workflow works perfectly.
Also, I did not see your response until just now but also found that this can be done using Python tool in Alteryx. Leaving this link below and some code if it is also helpful for others: https://curlconverter.com/
from ayx import Alteryx
import pandas as pd
import requests
headers = {
'accept': 'text/plain',
'Authorization': 'Bearer ************************************',
'Content-Type': 'application/json',
}
json_data = {
'phoneNumber': '***-***-****',
}
response = requests.post('https://api.openpeoplesearch.com/api/v1/Consumer/PhoneSearch', headers=headers, json=json_data)
# Note: json_data will not be serialized by requests
# exactly as it was in the original request.
#data = '{"phoneNumber":"**********"}'
#response = requests.post('https://api.openpeoplesearch.com/api/v1/Consumer/PhoneSearch', headers=headers, data=data)
data = [response]
df = pd.DataFrame(data)
Alteryx.write(df, 1)
I expect APIs support from almost any programming language, of course we care of those supported by Alteryx
Arnaldo