cURL (API) in Python

0

I'm accessing the URL API through cURL and I'm looking to do it through Python. I do not know if this can be done but it would solve my job a lot.

The steps I'm taking are: I enter this code to my terminal and it returns me the answer:

Code:

curl 'https://partners.com/api/v2/login' -d 'username=user&password=pass'

Answer:

{"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI1YTAxZGNlZjlkNmQ1ZTAwMDI3YWMyNGEifQ.zcC5w6SHL-PN4kZgnDVh75jqLJ5BsKP27YZi7xaiels","token_type":"bearer","user_id":"5a01dcef9d6d5e00027ac24a"}Imac-Office:~ Martin$ 

Now, the touch I have to copy it and put it where it says TOKEN

curl 'https://partners.com/api/v2/traffic-channels' -H 'Authorization: Bearer TOKEN' -d '{"trafficChannel":{"name":"tc10","status":0,"billedEvent":"ai","env":"desktop","dealType":"fixed_price","cost":2,"floor":2.5,"optimizeAllAdSources":true,"optimizeFor":"fillRate","publisher":"5a01e576becbf9000255f29c"}}'

I want to make a code in python where I can put everything together, something like this:

curl 'https://partners.com/api/v2/login' -d 'username=user&password=pass'

curl 'https://partners.com/api/v2/traffic-channels' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI1YTAxZGNlZjlkNmQ1ZTAwMDI3YWMyNGEifQ.zcC5w6SHL ' -d '{"trafficChannel":{"name":"tc10","status":0,"billedEvent":"ai","env":"desktop","dealType":"fixed_price","cost":2,"floor":2.5,"optimizeAllAdSources":true,"optimizeFor":"fillRate","publisher":"5a01e576becbf9000255f29c"}}'

That automatically captures the response of the token and pastes it into the next line of code.

Greetings and thanks

    
asked by Martin Bouhier 08.11.2017 в 13:40
source

0 answers