Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Open People Search | Alteryx API Connection

AlteryxUserFL
11 - Bolide

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? 

3 REPLIES 3
ArnaldoSandoval
12 - Quasar

Hi @AlteryxUserFL 

 

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:

  • I registered with OpenPeople creating my own account 🙂; this will allow me to consume their APIs and ableing me to write this reply.
  • The OpenPeople API Documentation is very detailed, unfortunatelly their examples are curl based, which challenges my Alteryx expertise.
  • The OpenPeople APIs catalog is also very valuable, this page is a catalog listing lots of their API, I logged to OpenPeople in order to be able to play with these APIs and understand their behaviour; testing these APIs within the OpenPeople site hides their handling of their authorization, more about this later.
  • If we scroll down their APIs catalog, its User section contains the API to retried our personal authentication code; so this is how I found my OpenPeople code to consume their APIs.

OpenPeople-02.png

OpenPeople-03.png

You probable already know this, anyhow, this is a one-off first step, getting our OpenPeople token, we will need it in Alteryx

  • Now, switched to OpenPeople Data Viewer page, and trigger a search for a single person across USA, as the interface shares with us the curl command, request and results.

OpenPeople-04.png

Problem:

  • As far as I know today, Alteryx is expecting an HTML end-point, not a command like "curl"
  • Now from the video we learned about the "Postman" and know how to use it with some clunkiness.
  • So we asked Dr Google "Does postman support curl?", and we got this hit: Running curl Examples in Postman and followed these instruction in our Postman.

Postman:

OpenPeople-05.png

  • The image above highlight Postman Client interface key items for our goal.
  • They were populated after the Import, still we have to apply some adjustments.
  • We noticed that the "Params" tab is empty, our search info was not automatically added here.
  • Also the Authorization tab is empty by default.

OpenPeople-06.png

  • The Headers shows 3 keys: accept; Authorization and Content-Type; the Authorization key is the same token OpenPeople assigned to our login credentials when we register; it is the same token shown above: NOTE: I obscured this token as it is associated to my login credentials, you should use the one assigned to yours; Adjustment: The authorization value appears as: Bearer ********* We have to copy the token we got at the User section explained above, just copy the token, excluding the quotes (") and replace all the asterisk.

OpenPeople-07.png

  • The Body tab containes the body of our request, the person details, all the Roberto Aguirre's in Miami, Florida (wow this API is powerful); the body itself is a JSon string with all the expected search parameters

OpenPeople-08.png

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:

  • If you listened to the video (API's in Alteryx), you should have a workflow like this one, processing "Guardian-API" calls.

OpenPeople-10.png

Basic tab: no changes

Header: Add the keys: accept, Authorization and Content-Type; copy them from "Postman"

OpenPeople-11.png

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)

OpenPeople-12.png

  • JSON Parse tool: no changes
  • Text to Columns tool: no changes
  • Filter tool no changes
  • Cross Tab tool; change this tool configuration as shown below:

OpenPeople-13.png

 

NOTES/COMMENTS:

  • I can't test any more, I ran out of free calls 😯🤣.
  • Interesting API, I was concerned with Personal Information but the application mask some personal fields, so you can't see the full details.
  • I replaced with '*' my authorization token in the Download tool; you should add yours for the tool to work.
  • You should enhance the Download tool to receive the search parameters from a variable.
  • Roberto Aguirre was a name I took randomly, Roberto is very popular and I expected Aguirre to be comun in Florida, with lot of Hispanic people; I did not try John Smith because they could be too much data.

 

hth

Arnaldo

 

 

 

 

 

AlteryxUserFL
11 - Bolide

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)
ArnaldoSandoval
12 - Quasar

Hi @AlteryxUserFL 

 

I expect APIs support from almost any programming language, of course we care of those supported by Alteryx 

 

Arnaldo

Labels