Add sample image in template header in whatsapp cloud API - node.js

I am doing a project using WhatsApp cloud API. I need to create a template with a media header. I have created a template with a media header without a sample image and it gets rejected. So I want to create a template with a sample image in Node JS.
Template with a media header
Add sample image for a template
curl -X POST "https://graph.facebook.com/v14.0/{whatsapp-business-account-ID}/message_templates
?name={template-name}
&language=en_US
&category=TRANSACTIONAL,
&components=[{
type:BODY,
text:{message-text}
},
{
type:HEADER,
format:IMAGE,
example:{header_handle:[{uploaded-image-file-url}]}
}],
&access_token={system-user-access-token}"
I want to add a sample image using Node JS (Not manually like the second picture).

header_handle requires a encrypted file upload provided by facebook.
This can be done by calling 2 apis.
First,
We have to create a session for the file to be uploaded.
For creating session refer this
After creating session, we will get session id to upload the original file to it.Response will look something like this:
{"id":"upload:MTphdHRhY2htZW50Ojlk2mJiZxUwLWV6MDUtNDIwMy05yTA3LWQ4ZDPmZGFkNTM0NT8=?sig=ARZqkGCA_uQMxC8nHKI"}
Second,We have to upload the file to
https://graph.facebook.com/v14.0/{above_id}
This will give a response something similar to
{"h":"2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"}
Finally,
{header_handle:["2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"]}
Should be added during the request to create template.
It worked for me.
See this for better understanding on how to do it.

The answer Provided by Aravindh is correct, you can follow This document from Meta to upload the Image you want.
Just make sure you use a supported type by WhatsApp API ( For WhatsApp Business Platform Cloud API , For WhatsApp Business Platform On-Premises API ) and the upload end point (file-type — The file's MIME type. Valid values are: image/jpeg, image/jpg, image/png, and video/mp4
)
Double Check if you are following exacly the types supported, for example in case of png, you need to set "file_type" to "image/png" no just "png" when creating the upload session.
I have tested it and it works for me.
Hope this helps

Related

Shopware 6 call api from backend

I am making a new backend page where you should be able to download an export.
I already got the the route and the export working. If I call my export action from curl with sw-access-key I get my download: store-api/v3/_action/orderer-export/77f40024cfd448d9a90063a75dc9fb2e
How do I make the download link with auth?
Update
I added a service and created it like:
vendor/shopware/administration/Resources/app/administration/src/module/sw-import-export/service/importExport.service.js
Also changed store-api to api in my DownloadRoute.php: #RouteScope(scopes={"api"})
Now I can use this new service to call my API and the the file contents as response. Still no download.
Looking at \Shopware\Core\Content\ImportExport\Controller\ImportExportActionController::download I finally got it.
Simply add defaults={"auth_required"=false} to your route:
#Route("/api/v{version}/_action/import-export/file/download", name="api.action.import_export.file.download", defaults={"auth_required"=false}, methods={"GET"})
Security Warning: If your download contains non public information you need to add a secure token or download link. Otherwise your download is free for anyone. Shopwares own ImportExport generates download links with a token. Have a look there.

How to upload an mp4 (or other video) to Imgur using the API?

I am using the Imgur API to upload images to albums, as part of a Reddit bot. However, when I try to upload MP4 files I get an error: "File type invalid (1)". Uploading the exact same MP4 file using the website works just fine.
I am using this endpoint to upload the file: POST https://api.imgur.com/3/image
https://apidocs.imgur.com/#c85c9dfc-7487-4de2-9ecd-66f727cf3139
The above comment is no longer correct -- You can indeed upload an MP4 using Imgur API
import requests
url = "https://api.imgur.com/3/upload"
payload = {'album': 'ALBUMID',
'type': 'file',
'disable_audio': '0'}
files = [
('video', open('/path/to/Video.mp4','rb'))
]
headers = {
'Authorization': 'Bearer BEARERTOKENHERE'
}
response = requests.request("POST", url, headers=headers, data = payload, files = files)
print(response.text.encode('utf8'))
The above works for me and uploads successfully. Something to note though, I have not figured out how to make the upload tied to my account, or within a specific album. It seems to be ignoring the album_id field. In other words, despite using the Bearer token, it appears to be navigating the API "anonymously".
From the imgur Help site, located here and last updated 2 months ago:
https://help.imgur.com/hc/en-us/articles/115000083326-What-files-can-I-upload-What-is-the-size-limit-
File Types
If you need help learning how to upload on Imgur, check out this help
article. You can upload any of the following files: JPEG, PNG, GIF, APNG, TIFF, MOV (desktop website only), MP4 (desktop website
only)
Imgur doesn't currently support uploads in the following
formats: WEBM GIFV
Explicitly, MP4s are only currently supported as uploaded manually via the website directly.
Unfortunately, that means imgur does not support MP4 types through any method other than the Desktop site at this current time.
I agree with a comment above. Now it is works great. Even you can upload the video without authorization. Just using a POST method https://api.imgur.com/3/upload. Pass a video file in body with image key. That's all.
Example in Postman

Make a S3 resource public read-only for some duration using the AWS SDK for node?

I have integrated S3 to my node app and upload certain documents on to S3. Need to share these documents with a third party.
Send the URLs to the third party via an API and they will download it immediately. I want to make the S3 objects public for some duration. How do i achieve this ?
S3 presigned URL is what you are looking for, you can use them to generate links for your third party with expiration time. I'm posting the reference links below
Presigned url AWS official documentation
A blog post which demonstrate presigned urls further
With #varnit's help i was able to figure out creating a public URL for certain duration.
I had another issue, get KEY from the resource URL.
Resolved that in Node using this:
AmazonS3URI(resourceUrl)
which returns something like this:
{
"uri":{
"protocol":"https:",
"slashes":true,
"auth":null,
"host":"bucket.s3.region.amazonaws.com",
"port":null,
"hostname":"bucket.s3.region.amazonaws.com",
"hash":null,
"search":null,
"query":null,
"pathname":"/private/region%xxxxxx/file",
"path":"/private/region%xxxxx/file",
"href":"https://bucket.s3.region.amazonaws.com/private/region%xxxxxx/file"
},
"isPathStyle":false,
"bucket":"aaaa-bbbb-ccc",
"key":"private/xxxxx:yyyyy/file",
"region":"region"
}

php library for flickr API

I am banging my head trying to use Flickr API...
My goal is to be able to upload images and create albums in my Flickr account from my website...
I tried the phpFlickr library but apparently it needs updates for getting authenticated tokens...It keeps giving me "Invalid auth token".
I did some reading on how to get tokens and using DPZFlickr managed to get oauth_token & oauth_verifier but failed to exchange that with an access token...It also failed in uploading any photo to my account using the included upload.php example (Giving me an "empty" error!).
After digging in DBZ flickr.php code, I managed to get this error when trying to upload to Flickr: "oauth_problem=signature_invalid&"
So I began to search how to create a valid signature to eventually get a valid access token...and concluded that it is quite some work to be done here if I am going to build everything from scratch.
So my question is: Are there any updated php libraries that I can use to successfully create albums and upload photos to my Flickr account? Or should I go ahead and try building one?
OK..I finally got it to work with the DPZ library.
For future reference anybody facing the same problem as I had:
I managed to create an album using DPZFlickr by changing the method in auth.php to flickr.photosets.create....which indicated that the library correctly generates an access token with write permission..
However, the upload example kept giving me the "Invalid signature" error....
I checked the code. Flickr.php correctly unsets the photo parameter before signing the request then adds it back and submits the request which is exactly as indicated in: www.flickr.com/services/api/upload.api.html
I found a discussion in https://www.flickr.com/groups/51035612836#N01/discuss/72157650261711318/ that cleared out that the error was not actually a signature problem, but rather the 'photo' parameter that is being sent is the problem. It's just that Flickr doesn't know what to do with the photo parameter so it sends the signature error.
So what' wrong with the photo parameter?
Flickr API requires that the image has to be sent in binary form...The DBZ library, Flickr.php script line 677, does the hard work for us using the cURL function in php (http://au.php.net/manual/en/function.curl-setopt.php).
It sends the $parameters (which includes the uploaded photo) to the post field of the http request which should do the upload in binary format for us.
However, a brilliant comment I found in CURL PHP send image
states that:
"CURLOPT_SAFE_UPLOAD defaulted to true in 5.6.0... so you will need to add curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); before setting CURLOPT_POSTFIELDS"
Checking the manual: http://au.php.net/manual/en/function.curl-setopt.php
it says:
"Added in PHP 5.5.0 with FALSE as the default value. PHP 5.6.0 changes the default value to TRUE."
So if your php version is 5.5.0 the library will work just fine whilst if using version PHP 5.6.0 you need to add a line before 677 in Flickr.php to change the CURLOPT_SAFE_UPLOAD to false (that's why the library works with some and others not).
To solve the issue...Just add this line before line 677 in Flickr.php:
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
That's it. (-:

File not supported error while uploading profile image file to IBM Connections using REST API

I'm trying to upload a jpeg file for profile image using the Profiles REST API to IBM Connections_v5.0. I however get an error message "The type of the photo file you provided is not supported".
I'm however able to upload the same file directly using the Connections UI interface directly. I'm setting the MIME type correctly as "image/jpeg".
Also tried with GIF and PNG images but get the same error message.
Any pointers would be very helpful.
I'm just using FF restclient addon to fire a REST call. So basically doing a PUT on /profiles/photo.do?key=....
Content-Type is set as "image/jpeg" and the payload consists of the image data in binary (base 64) encoded.
The payload should just be the binary of the image, there is no need to Base64 encode it.
You should refer to Adding a Profile Photo
You need to use a Key (great stackoverflow post here)
If you know the key for a user's profile you can do the following:
key — This is generated by Connections itself during the population
process. It is used to define the users profile within the context of
Profiles and provides Connections with the ability to associate
content with a user when the users LDAP information has been altered.
It provides a separation of identity and helps facilitate user content
synchronization for Connections.
Once you have a key, you make the following request
URL: https://profiles.enterprise.example.com/profiles/photo.do?key=
b559403a-9r32-2c81-c99w-ppq8bb69442
METHOD: PUT
CONTENT-TYPE: image/png
input the binary content on the stream
you should be able to use "image/jpeg", "image/jpg", "image/png" or "image/gif"
If you have an error after the PUT method, you should add the SystemOut.log lines which are relevant.

Resources