Downloading attachment from card at Trello Python3 - python-3.x

I've got a problem that unables me to download attachment.
Via API I can Upload file as attachment, but instead of authorising via Oauth, I can get attachment, by it's ID, i got accept, but I cannot in response got any answer.
The way I do:
response = requests.get(f'https://api.trello.com/1/{card_id}/attachments/{id_of_attachment}', header, allow_redirects=True, auth=self.o_oauth)
header is dictionary which is:
empty,
or authorisation,
or authorisation and "fields": url_of_attachment
On every of this questions to Trelo I got access, and 200 Response. But in response there was no place where I could find my file (I'm uploading this in the same test, and I got accept).
Where, and how should I look for content?

Related

Error 400 Invalid request with upload url but file is properly send to sharepoint

I try to send a file to sharepoint using the Microsoft Graph API resumable file upload :
First, I create my upload session POST: https://graph.microsoft.com/v1.0/me/drive/root:/{itemid}/createUploadSession and I get my upload url, no problem here.
I call my upload url PUT: https://xxx-my.sharepoint.com/personal/xxx_onmicrosoft_com/_api/v2.0/drive/items/xxxxxxxxxx/uploadSession?guid='xxxx'&overwrite=True&rename=False&dc=0&tempauth=xxx with some parameters: Content-Length and Content-Range
I get this error, code 400 : {"error":{"code":"invalidRequest","message":"Invalid request"}} but if I take a look to my sharepoint, the upload did create it! I tried to add or remove parameters, change PUT to POST but of course, it's not working (got DeferCommit was set to false for this upload session., which seems to be normal if I call the upload url with POST).
If I look to the error message, I just have Bad Request with no more informations. I don't know what I'm doing wrong or what I'm missing. If you have some insights, please do tell!!
I found what was missing! I need to add this header to my request: Accept with the value application/json. Now it works like a charm!

Tableau Image Response Into ADF

I'm using the Tableau REST API to get an image of a workbook view.
Testing the endpoint in Postman, I get the image perfectly fine back and the Content-Type is "image/png". Now I want to send that same image to an email with an ADF pipeline, the response I get seems to be binary from the Web activity:
"{ Response": "�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0003�\u0000\u0000\u0003 ...})
I've been seeing online that the above response is of : "application/octet-stream". Even though the content-type response is of "image/png" in the response in ADF AND Postman.
So I create another web activity which is a Send Email Web activity. In the body, I send the data in a JSON format to a Logic App Send email task.
I want to embed the image into the email using the "img" HTML tag. I set the response of the Tableau image and send it with basee64 encoding:
#json(concat('{"emailAddress": "myemail#email.com", "subject": "Tableau Data","messageBody":"<img src=\"data:image/png;base64,',base64(activity('Get View').output.Response),'\" >"}'))
Once it sends it, I get no image at all.
What do I need to do in order to get the image on the email? I feel like I'm missing some encoding to the response or do I need to save it first to a storage blob and then send from there?

Body of response with statuscode 401

I'm trying to enable some kind of "voice unlinking" (which should remove the access token from the google assistant) for my google action. I'm using the webhook fulfillment via Dialogflow and I'd like to send a response text like "Okay, your account linking got removed."
To do so, I'm currently trying to send a response using the status code 401, but it seems that my response body gets either ignored by the assistant or filtered along the way.
So my question is:
Is there a way to add any body information to a response with status code 401 or are there other ways to achieve the removing of access tokens via response?

Spotify API Token Scope Issue

I have been at this for sometime now and wanted to see if anyone had and idea of what I could be doing wrong. What I am trying to do is add a song to a playlist using the provided Spotify Web APIs. According to the documentation on this https://developer.spotify.com/documentation/web-api/reference/playlists/add-tracks-to-playlist/ I need to establish the scope of the user.
"adding tracks to the current user’s private playlist (including collaborative playlists) requires the playlist-modify-private scope" I have created the playlist as collaborative and I am using the login credentials of my personal account to reach this playlist I created. all this is under the same login.
What I am finding is that my scope is not getting added to my token on my call for my token causes a 403 error when I try to add the song.
Here is what that call looks like
https://accounts.spotify.com/authorize/?client_id=mynumber&response_type=code&scope=playlist-modify-private&redirect_uri=http:%2F%2Flocalhost:55141/Home/GetToken/
here are the docs on using authorization to get the correct token.
https://accounts.spotify.com/authorize/?client_id=894400c20b884591a05a8f2432cca4f0&response_type=code&scope=playlist-modify-private&redirect_uri=http:%2F%2Flocalhost:55141/Home/GetToken/
further more if I go into the dev support here
https://developer.spotify.com/documentation/web-api/reference/playlists/add-tracks-to-playlist/
and click the green try button and then request a new token it works.
Bottom line some how my request is not taking my scope request. Any Ideas?
Thanks
To get the token with a specific scope you need to go to the authorize endpoint and get the code. The code is what you want to get to be able http post to the endpoint https://accounts.spotify.com/api/token and get a token with your desired scopes. You can simply get the code by pasting a url like this in your browser...
https://accounts.spotify.com/authorize?client_id=<client_id>&response_type=code&scope=streaming%20user-read-email%20user-read-private&redirect_uri=<redirect_uri>
Only add %20 in between scopes if you have multiple ones
You will then be sent to spotify's website and they'll verify you want to do this. Once you verify it your browser will redirect you to what you set the redirect_uri to be in the url above. At the end of the url that you are sent to, you should be able to see the parameter name code with the code value assigned to it. You then get that code and put it in your http post body params to the https://accounts.spotify.com/api/token endpoint. Make sure you accurately follow the query params requirements in your post method.
An example of the post in python using the requests library:
authorization = requests.post(
"https://accounts.spotify.com/api/token",
auth=(client_id, client_secret),
data={
"grant_type": "authorization_code",
"code": <code>,
"redirect_uri": <redirect_uri>
},
)
authorization_JSON = authorization.json()
return authorization_JSON["access_token"]
In the end you should get a json that shows the scopes you set a long with a refresh the token later on to make more requests.
I know this answer is quite late but I was experiencing the same issue as well which is how I came across this question. I hope this helps anyone that sees this at a later date.
Source: https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow

Where is the host and port coming from when I am reading Direct Line API doc from Microsoft Bot Framework

I noticed the Direct Line request url is like this: https://localhost:8011/api/ in the documention. What should replace it with?
I have deployed a todoBot example project from botbuilder Examples folder. And I have created a bot in My bots section, the ending point is: http://www.bigluntan.com:3978/api/messages. I have tested in Test connection to your bot section, it is working when I type something and send it. Right now, I want to give Direct Line a try. So I added Direct Line to Channels. But the most confused part is, how do I call this Direct Line api, cause the ending point is different than my bot's ending point.
The base URL is https://directline.botframework.com, so for instance, the POST request to get a new conversationId should be https://directline.botframework.com/api/conversations/
The request headers should include the Content-Type and also the following:
Authorization: BotConnector < Your secret >
where your secret is the code which was created when you created a Direct Line channel for your registered Bot (see image below). e.g.
Content-Type: application/json; charset=utf-8
Authorization: BotConnector pB7INWcXQjA.cwA.RF4.cglOUNHUOzWVv0Rlk3ovFNhtp1JPz1Zx9jmu8vX7zXs
Once you get a conversationId, you can POST a message using the URL https://directline.botframework.com/api/conversations/< conversationId >/messages
The body of the request should include the message text. You will not get the reply in the POST response. Instead, you need to get it by sending a GET to
https://directline.botframework.com/api/conversations/< conversationId >/messages. From there, you can get the "from" value in your first message, and use it in subsequent calls to the same conversation (otherwise the bot will not recognise the state, and just keep repeating the first reply message), e.g.
{
text: "yes",
from: "EQxvIzZOspA"
}
I found this out by trial and error. If you want to use the direct line api you should try https://directline.botframework.com
as the base URL

Resources