API help with Python

165 views
Skip to first unread message

Moo

unread,
Jul 18, 2018, 6:19:54 AM7/18/18
to Artsy API Developers
Hi I'm trying to use Artsy API for a self project, but I'm having trouble getting the data. Not really sure how to use the API with python and I can't seem to find any documentation on it.
The only module I'm using on Python right now is requests, and I manage to get the token.

When I run the example line: res = requests.get("https://api.artsy.net/api/artists/andy-warhol"), I get {'type': 'auth_error', 'message': 'An application token or a user is required.'}.
I try appending the token at different parts of the URL, but with no luck. I'm pretty new to using API. Some help would be awesome. 

Thanks

Daniel Doubrovkine

unread,
Jul 18, 2018, 6:53:35 AM7/18/18
to ng...@unlv.nevada.edu, Artsy API Developers
Not sure about Python specifically, but there're examples with curl in https://developers.artsy.net/docs/authentication that you should try first with the token, just to make sure the token is valid.

For xapp tokens you have to supply them in the header as X-Xapp-Token. This SO seems to say how to do it.

If you figure everything out we'd love to extend the docs with python examples! The developer site is open-source, so you can either contribute or open an issue with some working code and we'll do it time permitting, https://github.com/artsy/doppler.

cheers
dB.



[A.]    Daniel Doubrovkine (dB.)

         CTO @ Artsy   

         d...@artsy.net

         @dblockdotorg

         code.dblock.org


PS: I'm running the NYC TCS Marathon in 2018 for TeamForKids charity. Please donate here.




--
Find all info about the Artsy.net API at https://developers.artsy.net.
---
You received this message because you are subscribed to the Google Groups "Artsy API Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to artsy-api-develo...@googlegroups.com.
To post to this group, send email to artsy-api-...@googlegroups.com.
Visit this group at https://groups.google.com/group/artsy-api-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/artsy-api-developers/e16237ef-bc29-4382-b6e9-c7bd544b3c32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dr Worm

unread,
Apr 5, 2019, 2:51:50 PM4/5/19
to Artsy API Developers
import json, requests

client_id
= 'your_client_id'
client_secret
= 'your_client_secret'
api_url
= 'https://api.artsy.net/api/tokens/xapp_token'
##THIS BIT IS GETTING THE TOKEN
 r
= requests.post(api_url,
                   data
={
                       
"client_id":client_id,
                       
"client_secret":client_secret
                   
})

j
= json.loads(r.text)
token
= j["token"]

##THIS BIT GETS THE INFORMATION
##YOU WERE TYPING IN THE NAME OF THE ARTIST AND I BELIEVE IT SHOULD BE THE ID
headers
= {"X-Xapp-Token" : token}
url
= "https://api.artsy.net/api/artists"
r
= requests.get(url, headers = headers)

data
= json.loads(r.text)

But when I get the data from artists. All of the names are either empty or have numbers. Even when i go to the json file directly, i only see like 4 different artists.

Daniel Doubrovkine

unread,
Apr 5, 2019, 4:11:19 PM4/5/19
to Dr Worm, Artsy API Developers
This is actually working as expected.

You can try this in the browser and you will see that https://api.artsy.net/api/artists is a paginated result of 135,828 artists. The first two should probably not exist (an artist without a name and an artist with the name "artist"). The third one is legit, https://www.artsy.net/artist/00100011 is an actual artist, the art world is fun like that ;)

Try https://api.artsy.net/api/artists?sample=1 for a random, more interesting artist.

cheers
dB.

[A.]    Daniel Doubrovkine (dB.)

         CTO @ Artsy   

         d...@artsy.net

         @dblockdotorg

         code.dblock.org


--
Find all info about the Artsy.net API at https://developers.artsy.net.
---
You received this message because you are subscribed to the Google Groups "Artsy API Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to artsy-api-develo...@googlegroups.com.
To post to this group, send email to artsy-api-...@googlegroups.com.
Visit this group at https://groups.google.com/group/artsy-api-developers.

Dr Worm

unread,
Apr 5, 2019, 4:54:46 PM4/5/19
to Artsy API Developers
Okay i see how it works now. Thanks you! just made it a lot easier for me.
To unsubscribe from this group and stop receiving emails from it, send an email to artsy-api-developers+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages