RustyShackleford
RustyShackleford

Reputation: 3677

How to develop API if API URL requires API key integration into URL?

I need to make a basic GET call for this API(https://www.activecampaign.com/api/example.php?call=contact_list). The API documentation is unclear as too how to pass the API key into the URL as well as the other parameters.

Furthermore the endpoint in the API documentation is only part of the solution. I got a URL in my API settings which I think is part of the endpoint. The URL looks like this:

https://url.api-us1.com

So how do I get this API to work?

Here is my code so far:

import requests

api_key = '123abc'
url = 'https://url.api-us1.com/admin/api.php?api_action=address_list'


r = requests.get(url, params=api_key)

The error I get back from the response object is:

<?xml version='1.0' encoding='utf-8'?>\n<root><result_code>0</result_code><result_message>You are not authorized to access this file</result_message><result_output>xml</result_output></root>"

The API also does not provide what headers to pass.

Thank you in advance.

Upvotes: 1

Views: 191

Answers (1)

kindall
kindall

Reputation: 184250

As the documentation says, the API key needs to go in your URL, not in the body of the request. E.g.

url = 'https://url.api-us1.com/admin/api.php?api_action=address_list&api_key' + api_key

Upvotes: 1

Related Questions