Skip to main content

Receiving 400 bad request from AWS Lambda

  • 16 April 2022
  • 4 replies
  • 2579 views

Using the dashboard API I have a request that works perfectly in postman but I’m having trouble getting any results when sending from and AWS Lambda Function. 

When I use the below code I get “HTTP 400: Bad Request (Unable to create definition from arguments)”

 


    event_dict = str({"event_type":"Activate%20Lesson"})
    url = f"https://amplitude.com/api/2/events/segmentation?e={event_dict}&start=20201201&end=20201231&i=1"
    
    payload=''
    headers = urllib3.make_headers(basic_auth='XXXXXXXXXXXXX:XXXXXXXXXXXXX')

    response = http.request('GET',
                        url,
                        body = payload,
                        headers = headers,
                        retries = False)

    res_data = response.data
    print(headers)
    print(res_data)
    print(url)
    return res_data
 

 

 

When I use below code I get an empty response:

 

    event_dict = str({"event_type":"Activate%20Lesson"})
    url = f"https://amplitude.com/api/2/events/segmentation?e={event_dict}&start=20201201&end=20201231&i=1"
    
    payload=''headers = {'Authentication' : 'Basic XXXXXXXXXXXXXXX:XXXXXXXXXXXXXX’}

    response = http.request('GET',
                        url,
                        body = payload,
                        headers = headers,
                        retries = False)

    res_data = response.data
    print(headers)
    print(res_data)
    print(url)
    return res_data

 

 

Again, when I test this endpoint in Postman I’m getting the JSON  response as expected. I could use some input on troubleshooting.

Thanks for posting here @doeggles 😀 Here are a few other similar error codes that were resolved that I found by running a search in this community. Please keep us posted as you make progress. 

 


Hi!

 

Which Dashboard API endpoint are you making this request to for example, Event Segmentation, Funnel or User Activity?

 

Best,

Sydney


Hi!

 

Which Dashboard API endpoint are you making this request to for example, Event Segmentation, Funnel or User Activity?

 

Best,

Sydney

This is the event segmentation endpoint @sydney.koh 


Hi! 

Apologies for the delay! It is the case that I won't be able to walk you through coding the connection on a python script as that would be out of my scope. I can share with you an example that my colleague did provide to another customer that might help you!

import requests response = requests.get('https://amplitude.com/api/3/chart/CHART_ID/query', auth=('api_key', 'secret_key')) print(response.json())

I also confirmed that the above example is still valid using a curl converter: https://curl.trillworks.com/#

Hope the example helps! If not, please share more of where the script is failing and perhaps I can look up additional resources online.

 

Also, if there are any other community users out there who can use python and have any tips feel free to respond to this thread with any tips or suggestions!

Best,

Sydney

 

 


Reply