PHP fails to POST to Web API using curl

Asked 1 months ago, Updated 1 months ago, 7 views

I can't skip the message to chatwork even if I execute the code below.
I added var_dump to the option settings, but I didn't know the cause because they were all true.

Could you give me some advice about the cause?

//***Create Chatbot: [Send msg to your chatwork board once members are registered in mikan's DB]
    header("Content-type:text/html; charset=utf-8"; // To prevent garbled characters when displaying a response browser
    $header=array('Content-Type: application/x-www-form-urlencoded', 'X-ChatWorkToken: My API Token');
    $url=" {room_id}/messages"; // My room room_id
    $ch = curl_init($url);
      'body' = > 'API collaboration completed',
      'self_unread' = > '0'
    $body_data=$data=http_build_query($body, "", "&");

    // Configuring [TODO] HTTP Request Header Information
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); // To string to display status code on error


      echo 'Curl error'.curl_error($ch);
      $err_msg[] = 'chatwork collaboration failed'; // This variable is defined elsewhere from the code listed.

    //****** Create Chatbot So far****

php api php-curl

2022-09-30 11:16

1 Answers

The URL to the Chatwork API was incorrect! {room_id}/messages

Remove the room_id parentheses {} from the above URL

After correcting the description, the request has been accepted!

2022-09-30 11:16

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.