Mannyxpress

RingCentral Send Fax

Nov 27th, 2019
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://forums.developers.ringcentral.com/questions/9012/sending-a-fax-attachment-using-powershell.html
  2.  
  3. $todestination = [pscustomobject]@()
  4. $todestination += @{
  5.     phoneNumber = "+14435551212"
  6.     name = "Test Recipient"
  7. }
  8.  
  9. ### CONVERT FILE CONTENT TO BASE64 STRING
  10. $FilePath = "$($env:TEMP)\TestFax.PDF"
  11. $objFile = Get-ItemProperty -Path $FilePath
  12. $FileData = [Convert]::ToBase64String([IO.File]::ReadAllBytes($FilePath))
  13.  
  14. $RingCentralSendFaxJson = [pscustomobject]@{}
  15. Add-Member -InputObject $RingCentralSendFaxJson -MemberType NoteProperty -Name to -Value $todestination
  16. Add-Member -InputObject $RingCentralSendFaxJson -MemberType NoteProperty -Name faxResolution -Value "High"
  17.  
  18. $RingCentralSendFaxJson = $RingCentralSendFaxJson | ConvertTo-Json
  19.  
  20. $LF = "`r`n";
  21. $boundary = "Boundry_$([System.Guid]::NewGuid().ToString();)"
  22.  
  23. # Need to package the message body in multipart/mixed format
  24. $RingCentralSendFax = (
  25.     "--$($boundary)",
  26.     "Content-Type: application/json",
  27.     "",    
  28.     $RingCentralSendFaxJson,
  29.     "",
  30.     "--$($boundary)",
  31.     "Content-Disposition: form-data; name=""attachment""; filename=""$($objFile.Name)""",
  32.     "Content-Transfer-Encoding: binary",
  33.     "Content-Type: application/octet-stream",
  34.     "",
  35.     "$FileData",
  36.     "",
  37.  
  38.     "--$($boundary)--"
  39. ) -join $LF
  40.  
  41. $accountId = "~"
  42. $extensionId = "~"
  43.  
  44. #Send the text message
  45. $sendresponse = Invoke-RestMethod -Uri "https://platform.devtest.ringcentral.com/restapi/v1.0/account/$($accountId)/extension/$($extensionId)/fax" -Method Post -ContentType "multipart/mixed; boundary=$($boundary)" -Body $RingCentralSendFax -Headers $accesstoken.Header
RAW Paste Data