dongruidian3064 2017-04-03 12:09
浏览 54
已采纳

Guy to ryver api

Hello guys i've been pulling my hair for this problem. I'm accessing an api from ryver to send post chat messages for automated notification. I'm following this doc https://support.ryver.com/chatmessage-api/ and I'm using laravel 5.1 with Guzzle and here's my code if it helps

$client = new Client();
        $postData = \GuzzleHttp\json_encode(['JSON Payload' => ['body' => 'test123']]);



        $options = [
            'json' => $postData
        ];

        $request = $client->post('https://somecompany.ryver.com/api/1/odata.svc/workrooms(1099207)/Chat.PostMessage()', $options);
        $request->setHeader('Content-Type', 'application/json');
        $request->setHeader('Accept', 'application/json');
        $request->setHeader('Authorization', 'Basic Base64codehere');

        $response = $request->send();

It always returns a [status code] 400, Please help :( Thank you and have a great day!

  • 写回答

2条回答 默认 最新

  • duanjianqu3685 2017-04-03 12:43
    关注

    Fixed it :) I just need to stringfy the JSON to make it work and set body the JSON. here's the code.

    $client = new Client();
            $postData = '{
            "body":"**Update!**
    > ** Test success for ryver integration.",
              "extras": {
                "from": {
                  "__descriptor":"Developer",
                  "avatarUrl":"https://cdn2.f-cdn.com/ppic/4973381/logo/4389970/developer_avatar.png"
                } 
              }
            }';
            $request = $client->post('https://company.ryver.com/api/1/odata.svc/workrooms(1098712)/Chat.PostMessage()',[
                'Content-Type' => 'application/json',
                'Accept' => 'application/json',
                'Authorization' => 'Basic base64'
            ]);
    
            $request->setBody($postData);
    
            $response = $request->send();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog