0

I have a problem with send message to Microsoft Teams. I followed the Microsoft Docs - https://learn.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-beta&tabs=http and something is not working.

I wrote following code:

$aToken = getAccessToken();

$dataArray = [
    "body" => [
        "content" => 'Hello World!'
    ]
];
$dataJSON = json_encode($dataArray, true);

$CURLHeaders = [
    'Content-Type: application/json',
    'Content-Length: ' . strlen($dataJSON),
    'Authorization: ' . $aToken,
];


$ch = curl_init($postURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_KEEP_SENDING_ON_ERROR, true);
curl_setopt($ch, CURLOPT_HTTPGET, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJSON);
curl_setopt($ch, CURLOPT_HTTPHEADER, $CURLHeaders);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

and my $CURLHeader is:

(
    [0] => Content-Type: application/json
    [1] => Content-Length: 35
    [2] => Authorization: Bearer eyJ0eXAiO...
)

and $dataJSON is: {"body":{"content":"Hello World!"}}

After send it I get the message:

{
  "error": {
    "code": "UnknownError",
    "message": "",
    "innerError": {
      "request-id": "88094f5d-1bcb-4875-9d49-880db19a146b",
      "date": "2020-04-14T16:00:28"
    }
  }
}

Something is wrong, but I don't know what...

sowixx
  • 1
  • 1
  • I hate API's that return things like "Unknown Error". Literally nothing you can do but call the API provider and ask them what the error is. That said I have several times had curl issue doe to SSL connections not validating. So worth a once over: https://stackoverflow.com/questions/29822686/curl-error-60-ssl-certificate-unable-to-get-local-issuer-certificate – danielson317 Apr 14 '20 at 16:28

0 Answers0