Etsy API python image upload - python

does anyone use python for adding listings to Etsy using API?
I am using requests_oauthlib, but keep getting error when want to upload image to listing. Other functions, like listing creation etc. are working. Code of image upload:
self.oauth = OAuth1(self.api_key,
client_secret=self.api_secret,
resource_owner_key=self.oauth_token,
resource_owner_secret=self.oauth_token_secret)
def upload_picture(self):
url = "https://openapi.etsy.com/v2/listings/{listing_id}/images"
headers = {
"Content-Type": "multipart/form-data",
}
request = {
'image': ('img8.jpg', open('./img8.jpg', 'rb'), 'image/jpeg'),
}
r = requests.post(url=url, params=request, auth=self.oauth, headers=headers)
print(r.content)
error:
oauth_problem=signature_invalid
Thanks in advance!

I wasn't able to do it like that. I'm not sure why.
But below worked for me:
etsy = OAuth1Session(
ApplicationKey,
ApplicationSecret,
token, token_secret
)
url = "https://openapi.etsy.com/v2/listings/{listing_id}/images"
request = { 'image': open('./img8.jpg', 'rb') }
response = etsy.post(url, files = request)
I'm new to both OAuth & Etsy API

Related

How to add tags to image uploaded to imgur api from python?

I am programming a bot so that I can upload local images to my Imgur account, but I also want to add tags of each image from Python
Here is my code:
import requests
import base64
headers1 = {'Authorization': 'Bearer Xxxx',}
params = {
'title':f'uwu',
'description':'hello',
'name':'Hey',
'add_tags':'Fortnite',
'image': base64.b64encode(open('cosmetico.png', 'rb').read())}
r = requests.post(f'https://api.imgur.com/3/image', headers=headers1, data=params)
data = r.json()["data"]["link"]
id = r.json()["data"]["id"]
I have tried to add add_tags or tags but none work.
I would like to be able to add the tags:
But I can't find a way to do it.

Unable to set payload to match with required format by server

I'm trying to download a excel file using a python request.
Below is the actual payload pass by web browser when I download required excel file manually.
I'm using below python code to do the same via automation.
import requests
import json
s = requests.Session()
response = s.get(url)
if response.status_code!=200:
return 'loading error!'
collectionId = response.content['collectionId']
payload = {
"collectionId": collectionId
}
response = s.post(url, json=payload)
Here I'm getting status code 400.
Can someone please help me to set payload to match with below snapshot.

Can't generate facebook access token

I need to generate the Facebook access token for a project.
Code:
import requests
import json
url = 'https://graph.facebook.com/oauth/access_token'
payload = {
'grant_type': 'client_credentials',
'client_id': 'clientid',
'client_secret': 'secret'
}
response = requests.post(url, json=payload)
print (response.json()['access_token'])
What I'm getting as output is my id|type, after research I found that it is due to the 'client_credential' request. I need to generate access tokens for a project (I want to use them to find likes etc). Any help would be appreciated, it's my first time attempting a project like this.
use [facebook-sdk.][1]
import facebook
app_id = 'YOUR_APP_ID'
app_secret = 'YOUR_APP_SECRET'
graph = facebook.GraphAPI()
# exactly what you're after ;-)
access_token = graph.get_app_access_token(app_id, app_secret)

Facebook API Upload Video by URL to Media Library

We have been searching for weeks but can't figure out how to upload videos or images with the API to the Media Library.
Eventually we need a video id generated by the upload API to use in our ad creative.
You can make a call to the advideos endpoint like so:
params = {
'file_url': YOUR_URL,
'access_token': YOUR_ACCESS_TOKEN
}
url = "https://graph.facebook.com/v13.0/{act_xxxxxxxxxx}/advideos"
r = requests.post(url, params)
response = r.json()

How to get data from amoCRM through API?

I am trying to get data through API from amoCRM system but I am having some problems and I am really tired.
The url: https://alamiri.amocrm.ru/api/v4/contacts
This API should return contacts of users that contain (first name, email, number, ...).
When I copy and paste the above link in the browser, I get the data and everything works fine but when I try to get that data in Python it returns the following:
{'detail': 'Invalid user name or password',
'status': 401,
'title': 'Unauthorized',
'type': 'https://httpstatus.es/401'
}
my code in python (Django framework):
import requests
import pprint
def get_contacts():
url = "https://alamiri.amocrm.com/api/v4/contacts"
api_key = "def50200c1f82415f4625f96e402d967b880e33938b94d6ad8edd6c305cda8a3fff80990871fba6aac89391440c6330a26768410a52b0e332b2c6a1b2e49cbe912132194d4bb8c4a15bb304c14f649f1149826fc0eeaf1311f23feeea1118cba72af36e76c22f30fa2fb81a4f0678cde451492504ba56eff9eb7af876e49ad721105a9b8bcc94400bf21e9c9f5de43a17daa439d5af64a9ae8e54bf8c7005f4f01515cfe8756a0ddd209fd91c4ca15bc336ef89523876dd39f6472f190f82b1ecd4d9d0cfccc6941c1ffb64d79e2e6dbec1b12331154a7b343ac10abfc05f432d09da878d41a37cdacc50b1f18419594e669854efa108c17384143a71a4d6739bad60cdc704728e2c0dce82ff5707d8d6c8f34ce59aa1855a42153b3703635881fe1cc4a037070846a938a9d124845e1f217fd63c15ed99c79cbee2646b4df8018addaf76289708587a2b182747423e490c3ec21b9fd78c69cd73f2d8985cf916fd50b24e23a1a722d61449a8cd2dea4d1e4d334b103fb311cd1bf5454e0a979c52e65c303baa96d70d655f9a0a300a7ba78c5cc1aa0234d88eefd9bb11e245615257b8955f031f76cec978ed0e3eb3c479b83b91bef4158728d"
login = "my-email-that-I-used-to-create-account-on-amocrm"
client_uuid = "e1899afa-85a8-45ca-93f9-7f4b26374a5d"
client_secret = "jUlw4E6H417MVuzsujIW39GXXjpLjratAwOEiaqPr3KDBKYwc9ZQLXK2UlhMcsuu"
headers = {
'login': login,
'client_uuid': client_uuid,
'client_id': client_uuid,
'client_secret': client_secret,
'grant_type': 'authorization_code',
'Authorization': f'Bearer {api_key}',
'session_id': "a8f1uutp26uipj414pfudab8cv",
'refresh_token': "def50200e673c8cf44d3c3a28df221ffb9d97c2f25cffefa09337953dc1fcc9b9aaa479235f8a6840cde697ecb58252452a22a7a71696665ff19a515db602601743799729b799a6d98d743ba33ab23b1d750ae479a068d16dd9d503062023a8406728c55afb37be5c4cf36df5a3c93bf06c9ff097c54db83d90308a92999669c80506590df2e609fa2aa2d55f3066d06efde55ab0a3c64c44a87743c5db3115632a6ecbd498cbc8012ccddfeabfe7ad9ad0f01664e72c434ccacd686be0e9582567ebdf6abb0cd4258c3b16bbb487222be774086398930ef18f2181a8b6d184a9ce61454710cc3bcaf01e978067a059aaa16c322c8d7b0e5cf34069b0f3ff1e2f5e5a665ec798d6f3d05bb95912528ef8b3230c3e2d03fbd1bbc4087b4bca54d050f876589b7c9fbc1c45199a58b021afa832776ed22637ea1e940dbb3156acec1c0b6320066a2045e26dcd5b6b169fb773ca11ebbb398b513ef8f6f04f973506a8c01c48dad944aadf078db881e8f7de959c187ae7cc41135e8c151bd89e5b8d71c2dc20ee6f282fefd8cb93fcd0f0942ab20ae457da41ea22fed3d881d21585219defc611531ca3909a632095e6c1d568f2408f4eab7b4b8aa90cb892d2253925b8682b9dce4f5",
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImJkZDk0MTA1NTc5NWY0YzAwOTNmZDAwMmIxMDE1NDczZTZiN2ZjZDBlZGJlNWJlMWJjMjYzYTY2YTY2MGRlODA0OWQ5MjM5ZTE4ODY2MmQyIn0.eyJhdWQiOiI3YjQ5MGYxOC0yYmU1LTRhNTUtYTc0ZS0xOTYzYzk2NDFiOTgiLCJqdGkiOiJiZGQ5NDEwNTU3OTVmNGMwMDkzZmQwMDJiMTAxNTQ3M2U2YjdmY2QwZWRiZTViZTFiYzI2M2E2NmE2NjBkZTgwNDlkOTIzOWUxODg2NjJkMiIsImlhdCI6MTYzNzMzOTYzMywibmJmIjoxNjM3MzM5NjMzLCJleHAiOjE2MzczNDIwMzMsInN1YiI6Ijc2NDM4ODQiLCJhY2NvdW50X2lkIjpudWxsLCJzY29wZXMiOlsiY2hhdHMiLCJjcm0iLCJub3RpZmljYXRpb25zIiwidW5zb3J0ZWQiLCJtYWlsIl19.VEz7bIXpbsL-iMCz51UgW6JU1rySQTIXBLf_xPdBcmMpR3yIL8raUgCjEBJ05E05lhMsYxxwKEYg2yN468jkqfz5wTfmRdGs9ECiVatZ6oMEJYFUn7AF5JaP0fQw18raZdAo8CQJfZS86IuHEYpU2k-lW5LmDC2dIIyZYe4irnln0KRw5_mgci4JNPEyeqzYADI0deqX-rraXFjFm6UP4KkByfOrgfopyOV8cIBA_34i4CWewbVQLJF4-HWGuKvaOH5Erjh-GUNViyCCuH2Q4F7dI6gwhAd2z2lEbbTR_x4oyRx04QA1YOZjI64SJQAaaIYDFLphr7D4V59w44zG1g",
"csrf_token": "def50200e00c062021bac6b78d51f10f45cc28add00268d9",
}
response = requests.get(url, headers=headers)
pprint.pprint(response.json())
get_contacts()
I am reading their documentation (amoCRM) and I tried a lot of things but none worked! 😥
https://www.amocrm.com/developers/content/platform/abilities/
I followed their instructions how to work with their API:
https://nova-amocrm.notion.site/894277ffef5940e7a5daadd2abc746c8
But I am stuck and I don't know how to solve this problem!
Any help please?
If you don't know what is amoCRM, then
Firstly, you should create an integration in your amoCRM account and use your google colab notebook link to redirection (or any other link).
enter image description here
Next, use the request to get refresh code and access token:
data = {'client_id' : '3d31ef87-...',
'client_secret' : 'xyEFPbRH5xw1...',
'grant_type' : 'authorization_code',
'code' : 'def50200ec88c8fe724cfc58ebd7e19...',
'redirect_uri' : 'https://colab.research.google.com/drive/...'}
new_url = 'https://your_domain/oauth2/access_token'
request = requests.post(new_url, data=data)
request_dict = json.loads(request.text)
refresh_code = request_dict['refresh_token']
access_token = request_dict['access_token']
Next, define the request headers:
api_call_headers = {'Authorization': 'Bearer ' + access_token}
And after that you can get any information using filters:
api_statuses_response = requests.get('https://alamiri.amocrm.ru/api/v4/contacts?filter[id]={id}&filter[created_at][from]={from}&filter[created_at][to]={to}', headers=api_call_headers, verify=True)
print(api_statuses_response.json())

Categories