Whatsapp Cloud API Update Profile Picture - api

I'm trying to upload an image as profile picture using WhatsApp Cloud API *.
After creating an application using WhatsApp Cloud API I'm not allowed to access neither using the regular application nor using Business Application. It says something like "try again in one hour". So I have to implement everything using the API.
After reading the docs and importing Postman Endpoints I found the one called Business Profiles > Update Business Profile
https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile
It has a field "profile_picture_url"and I have tried POSTing media https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/media and then with the given ID y used https://graph.facebook.com/{{Version}}/{{Media-ID}} to get the URL but it didn't work. The rest of the information is updated successfully
{
"messaging_product": "whatsapp",
"address": "",
"description": "Simple Bot",
"email": "...#gmail.com",
"websites": [
"https://..."
],
"profile_picture_url": "https://lookaside.fbsbx.com/..."
}
However if I try to send someone using the ID and the endpoint https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/messages it works fine.
And if I use Download Media Content with the URL in Postman it works fine too.
I don't know if I have misunderstood something or if it can't be done using the API.

It is mentioned in the Cloud API Documentation:
profile_picture_url (Optional): URL of the profile picture generated from a call to the Resumable Upload API.
But, i got it working using profile_picture_handle instead of profile_picture_url. So how do we get the profile_picture_handle?
Prerequisite:
Graph API token here. Or use your WhatsApp Cloud API token.
App ID, go Apps > Your App > Settings (sidebar menu) > Basic
Update Photo Profile:
Call POST https://graph.facebook.com/v14.0/{{appId}}/uploads?access_token={{token}}&file_length={{fileSizeInByte}}&file_type=image/jpeg
Save the session id you got, upload:XXXXXX?sig=XXXXXX.
Call POST https://graph.facebook.com/v14.0/{{sessionId}}, with the headers: Authorization=OAuth {{token}}, file_offset=0, Host=graph.facebook.com, Connection=close, Content-Type=multipart/form-data, and include your image file in the request body with type binary. If you using Postman, see image below (This is what I missed for hours).
Save the handle result you got, 4::XXX==:XXXXXX.
Finally, call POST https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile, with json request body: {"messaging_product": "whatsapp", "profile_picture_handle": "4::XXX==:XXXXXX"}
That's it, You can check the profile picture.

The last step you have to add your taken by selecting "Bearer" or else it will give you error. I had hard time on the last ones, do all the steps and then go to the following link and it should help.
https://web.postman.co/workspace/My-Workspace~a4ddb3b8-02a3-4132-8384-66e63e149b7b/request/22958165-506a0542-c845-41ac-b3fb-b8209fd6f53b

Related

Trying to make a page in a Confluence Space using REST API

I am trying to do a post request on my companies confluence to make a page using the REST API.
When I attempt to do it, I get a JSON response saying that it is forbidden.
I am able to make a page from the GUI, but not with the REST Api.
I have done Basic Authentication for the query.
Here is a picture of the request and the response.
My Question : how can I make the page on the confluence space with the rest Api?
I have tried: making a personal access token. And then using it with my request, but that didn't work either. 
The request body to create the page is a little different:
You should not use space as a container (only pages for comments as containers or attachments)
Do not use space id, just KEY
storage object should have a representation field and use its ID.
Here is the example:
{
"type":"page",
"title":"TEST SEITE 2",
"space":{
"key":"MY_SPACE_KEY"
},
"body":{
"storage":{
"value":"<p>This is my storage</p>",
"representation":"storage"
}
}
}

Sharepoint error: Likes are not supported in this item

I'm trying to create a Sharepoint iOS app and using the rest api I get the error "Likes are not supported in this item." after doing a POST to https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')/like.
Anyone knows more about this kind of error?
The Rating settings seems to be set correctly on the Sharepoint server, because the like option works correctly on the website, and also in the app I can see the likesCount properties on the response for the Rest API call https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234').
I don't think there is something wrong with the client app implementation, but it is something related to the Sharepoint configuration, although I haven't seen any more settings in regards to the Rating settings including the Sharepoint access for the mobile app.
The web seems to handle this using the Microsoft.Office.Server.ReputationModel.Reputation.setLike function which again works correctly on the web parts, but I couldn't find a way to do it from the mobile app.
To set Likes for the list item, we need use the API below with POST request.
https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')
And pass the data of the POST request as below.
var item = {
"__metadata": { "type": "SP.Data.PagesItem"},
"LikedByStringId": {"results": ["11"]},
"LikesCount": 2
};
Before set Likes for the item, we need get the "LikedByStringId" and "LikesCount" value of the list item using API below with GET request, then set the new one.
https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')
Check the article here: Demonstrates how to like/unlike resource via SharePoint REST API

Is it possible to get raw data from a Metabase MBQL / SQL query via the REST API?

Is there a Metabase REST API that takes a MBQL/SQL query and returns the raw data?
I can perform a MBQL query via the API in a 2-step process by doing the intermediate step of creating a Question via the Metabase web app UI and then querying the Question, but I haven't figured how how to combine MBQL with the REST API in a single step.
Some items I'd like to accomplish by having the MBQL in the API request instead of a UI-generated Question:
better version management as the MBQL query can be checked into source control with the code
better isolation as the API call won't be dependent on the question which can change
Here's some info on how to perform the 2-step process.
2-Step Process
The two step process is:
Use web app to create a MBQL/SQL Metabase Question
Use REST API to query existing Question created in web app using the Card API
Step 1) Creating Question via Web UI
Log into the web app and click the "New Question" button in the top menu.
Once your question has been created you will be directed to a URL like the following where :question-id is an integer.
Web UI endpoint: GET /question/:question-id
Note this value and use it in the API in the next step.
Note: an alternative for creating the card is to use the POST /api/card API endpoint per YakovL. This can be useful in some scenarios were UI questions/cards are desirable, but I'm also trying to avoid creating creating cards / questions in the first place, since I'm not planning on using the Metabase UI to consume them. Reasons to avoid cards for me include needing to perform extra work to verify the card query definitions haven't changed but still having the SQL in the code to create the cards, and generate a lot of unneeded question cards in the UI.
Step 2) REST API for Question Data
The API uses the term "card" for the Web UI "question" object, so make an API call to the following Card API:
API endpoint: POST /api/card/:card-id/query/:export-format
In this URL:
:card-id is the :question-id from the Web UI URL
:export-format can be json or another format
More information on the API is available in the API Documentation:
https://github.com/metabase/metabase/blob/master/docs/api-documentation.md
Question
Is there a way to do this directly by sending the MBQL/SQL query in the API request in a single step without a pre-existing Question/Card?
Querying via raw SQL and MBQL are both available via the POST /api/dataset/ API. The documentation for the endpoint mentions the query request definition but does not define it.
I ended up doing some more research and asking on the Metabase Discourse forum. The following examples were posted by sbelak.
Raw SQL Query
I was able to successfully make a native SQL query using the go-metabase SDK to make the following request:
POST /api/dataset
Content-Type: application/json
X-Metabase-Session: <sessionId>
{
"database": 1,
"native": {
"query": "SELECT COUNT(*) FROM orders"
},
type: "native"
}
Notes:
The POST /api/dataset does not set the response Content-Type header.
There is a POST /api/dataset/json endpoint, but that does not seem to accept the native property.
To set X-Metabase-Session see github.com/goauth/metabase.
MBQL
POST /api/dataset
Content-Type: application/json
X-Metabase-Session: <sessionId>
{
"database": 1,
"type": "query",
"query": {
"source-table": 2,
"breakout": [
[
"binning-strategy", ["field-id", 14], "default"
]
],
"aggregation": [["avg", ["field-id", 17]]]
}
}
Notes:
To set X-Metabase-Session see github.com/goauth/metabase.

Microsoft Graph: Uploading files to shared library instead of user's library?

In the documentation about Upload, these request options are listed:
PUT /me/drive/items/{parent-id}:/{filename}:/content
PUT /me/drive/root:/{parent-path}/{filename}:/content
PUT /me/drive/items/{parent-id}/children/{filename}/content
PUT /groups/<id>/drive/items/<parent-id>/children/<filename>/content
In the documentation about Resumable Uploads, Create an upload session show these options:
POST /me/drive/root:/{path-to-item}:/createUploadSession
POST /me/drive/items/{parent-item-id}:/{filename}:/createUploadSession
What if I have to upload to other (not 'me') drive? For example, the default shared library (https://mycompany.sharepoint.com/Shared%20Documents), which for any other porpoise besides uploading, the documentation says can be accessed like this:
/drives/{drive-id}/items/{item-id}
So, my question is: Is it possible to upload to "/Shared Documents"? If so, which is the right syntax for the PUT (small file) or POST (upload session)?
Perhaps something similar to this? (I just made this up, and it doesn't work)
PUT /drives/{drive-id}/items/{parent-id}/{filename}:/content
or (in case of an upload session):
POST /drives/{drive-id}/items/{parent-item-id}:/{filename}:/createUploadSession
For example, in the Graph Explorer, the response for something like this:
/v1.0/drives/THEDRIVEID/items/THEFOLDERID:/whatever.jpg:/createUploadSession
was:
{
"error": {
"code": "invalidRequest",
"message": "A valid path must be provided.",
"innerError": {
"request-id": "THERETURNEDID",
"date": "THERETURNEDDATE"
}
}
}
EDIT: Because the company's root can also be accessed as /drive/root/, I also tried (with no luck, in both 1.0 and beta):
/drive/root:/whatever.jpg:/createUploadSession
/drive/root/whatever.jpg:/createUploadSession
This is possible, but you need the right app permissions to be able to read/create files outside of the user's OneDrive. Instead of requesting Files.ReadWrite, you would need to request Sites.ReadWrite.All and then use /v1.0/drive/root:/file.bin:/createUploadSession.
You can also use the SharePoint Sites API in Microsoft Graph to access team site document libraries (other than the root site). However, this API is still in the beta version and should not be used in production apps.

Pinterest API get statistic for URL

I am trying to find a way to get statistic for the URL from Pinterest API.
Like facebook graph API: URL Object
Or linked in countserv endpoint:
https://www.linkedin.com/countserv/count/share?format=json&url=https://www.linkedin.com/pulse/breaking-5-major-boolean-syntax-changes-irina-shamaeva
I know it is possible because this site is returning the number of pins for given url:
https://www.sharedcount.com/#url=https%3A%2F%2Fwww.facebook.com%2F
Does anyone know how to get these data from Pinterest API?
There is no officially supported way to do this with the developer API. That said, the widgets use this for the count bubbles using this API
https://widgets.pinterest.com/v1/urls/count.json?url=<url>.
I wouldn't depend on it for anything important tho since it is unsupported and can change/be removed at any time.
You can get the number of pins calling this url
http://api.pinterest.com/v1/urls/count.json?callback=&url=http://stylehatch.co
It will return an object like this:
({"count": 0, "url": "http://stylehatch.co"})