Free Trial

Alteryx Designer Desktop Discussions

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

Translate Python Reddit Auth API to Download Tool

Anthony_A2
5 - Atom

Hello!

 

I am not having much luck translating the following Python API request into the Download tool to perform the same function. I am trying to receive an access token to use the Reddit API. I'm also having trouble inside of Python converting the json response to a dataframe to export and thought I'd use the download tool instead.  Can anyone advise how to set this up in the download tool? I think the beginning with BasicAuth is giving me trouble.

 

 

 

from ayx import Alteryx
import requests
import requests.auth
import pandas as pd

client_auth = requests.auth.HTTPBasicAuth('client_id', 'client_secret')
post_data = {"grant_type": "password", "username": "myusername", "password": "mypassword"}
headers = {"User-Agent": "ChangeMeClient/0.1 by myusername"}
response = requests.post("https://www.reddit.com/api/v1/access_token", auth=client_auth, data=post_data, headers=headers)
response.json()

 

 

 

In the download tool:

  • I enter the same URL
  • Select "Post"
  • Select my "grant_type", "username", and "password" fields in Payload
  • Select my "User-agent" field for headers
  • Have tried selecting my field "user" that had the client_id and client_secret combined in one field in different places. 
  • Receive a 401 response. 
1 REPLY 1
patrick_digan
17 - Castor
17 - Castor

@Anthony_A2 I think you're pretty close. Hopefully the attached gets you there. I got it working on my side with a dummy account I setup.

 

patrick_digan_0-1651079131094.png

 

As you figured out, the issue is the client id/secret. You need to combine them with a : and Base64 encode them. The Base64 encoder tool with alteryx sometimes has problems with more than 1 record, so I use the Blob Convert tools. In the header, you call it Authorization and then add "Basic " (with a space!) before your encoded client id/secret. The authorization is always the hardest part of setting up an api call. 

 

Labels
Top Solution Authors