1. ritesh desai
  2. PowerBuilder
  3. Wednesday, 30 November 2022 06:31 AM UTC

Hello, Have anyone upload pdf file using
whatsapp api

curl -X POST \
'https://graph.facebook.com/v15.0/FROM_PHONE_NUMBER_ID/media' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-F 'file=@/local/path/file.jpg;type=image/jpeg'
-F 'messaging_product=whatsapp'

 

how can i use this api in powerbuilder, It is work well in postman.

Who is viewing this page
ritesh desai Accepted Answer Pending Moderation
  1. Thursday, 1 December 2022 07:03 AM UTC
  2. PowerBuilder
  3. # 1

Actually , I want to use official WhatsApp api, It works fine with postman and also with chilkat activex in powerbuilder.

I want to try with powerbulider 2022 httpclient object.

Here is my sample code

string ls_mobile_no = '9198251*****'
long ll_len
string ls_data_header, ls_Boundary, ls_data, ls_encoded, ls_Url , ls_ReturnJson, ls_End
Constant String CRLF = Char(13) + Char(10)

ls_Boundary = "--------------060605070804060204050809"
ls_End = "~r~n~r~n" + ls_boundary + "--"

ls_data_header = CRLF + CRLF + ls_Boundary + CRLF
ls_data_header += 'Content-Disposition: form-data; name="file"; filename="@D:/bill.pdf"' + CRLF
ls_data_header += 'Content-Type: application/pdf' + CRLF

ls_data = ls_data_header


Blob lblob_filedata
long ll_Num
ll_Num = FileOpen("d:\bill.pdf", StreamMode!)
FileReadEx(ll_Num, lblob_filedata)
FileClose(ll_Num)

// encode the binary data
CoderObject lnv_CoderObject
lnv_CoderObject = Create CoderObject
//ls_encoded = lnv_CoderObject.Base64Encode(lblob_filedata)
//ls_data += CRLF + ls_encoded + CRLF

Blob lblb_data
lblb_data = Blob (ls_data_header,EncodingUTF8!) + lblob_filedata + Blob (ls_End,EncodingUTF8!)
//ls_data = ls_data_header + CRLF + ls_encoded + CRLF + ls_End
ll_len = len(lblb_data)

// ===============
string ls_token , ls_postdata
Long ll_rtn
HttpClient lo_http
lo_http = Create HttpClient

string ls_phone_id
ls_phone_id = '*********'

ls_token = i_token

lo_http.SetRequestHeader("Authorization", "Bearer " + ls_token)


String ls_Base64Str

string ls_json
ls_Url = "https://graph.facebook.com/v15.0/" + ls_phone_id + "/media?messaging_product=whatsapp&file=d:\bill.pdf"
lo_http.SetRequestHeader ( "Accept", "*/*" )
lo_http.SetRequestHeader ( "Content-Type", "multipart/form-data; boundary=" + ls_Boundary )
lo_http.SetRequestHeader ( "Connection", "keep-alive" )
lo_http.SetRequestHeader ( "Content-Length", string(ll_len) )

ll_rtn = lo_http.sendrequest( "POST", ls_Url , lblb_data)

lo_http.GetResponseBody(ls_ReturnJson)

pl. guide me

 

Comment
  1. Sivaprakash BKR
  2. Thursday, 1 December 2022 08:15 AM UTC
Any error message(s) that you get? Can you send us the what you get in return. ie values of ls_ReturnJson and ll_rtn
  1. Helpful
  1. ritesh desai
  2. Thursday, 1 December 2022 08:20 AM UTC
{"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1,"fbtrace_id":"Az61t_EFFc98V7DhA69Ly2Y"}}
  1. Helpful
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Thursday, 1 December 2022 05:12 AM UTC
  2. PowerBuilder
  3. # 2

Can you try Topwiz's RunandWait program to call the curl and check whether it works for you.

Happiness Always
BKR Sivaprakash

 

Comment
There are no comments made yet.
Kevin Ridley Accepted Answer Pending Moderation
  1. Wednesday, 30 November 2022 22:08 PM UTC
  2. PowerBuilder
  3. # 3

There was a session in Elevate 2022 called Integrate Twilio into Your PowerBuilder Applications to Send WhatsApp Messages .  I didn't catch the session but it may be useful for you to checkout the video.  I believe they are all uploaded now here:
https://www.appeon.com/conference/elevate-2022/agenda.html?ct=t%28Watch+Elevate+2022+Replay+Online%29&goal=0_47b6f83fed-e084450fc4-%5BLIST_EMAIL_ID%5D#gbvksl40mb

Comment
  1. Kevin Ridley
  2. Wednesday, 30 November 2022 22:11 PM UTC
I also did a quick search and found they do have a REST API that is free but they do charge per message.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.