-2

Using PHP curl, i'm trying to post message from php application to basecamp. When i run this code, it returns the error like this

Hmm, that isn’t right
You may have typed the URL incorrectly.
Check to make sure you’ve got the spelling, capitalization, etc. exactly right.

Code

<?php

$username = 'username';
$password = 'password';
$datastring = json_encode(array("name" => "from cURL"));

$URL = "https://basecamp.com/***/api/v1/projects/****.json";

   $ch = curl_init($URL);
   curl_setopt($ch, CURLOPT_MUTE, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
   //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
   curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $output = curl_exec($ch);
   curl_close($ch);
 echo $output;
?>

Not sure the API url is correct or not? How it can solve?

user3201764
  • 25
  • 1
  • 1
  • 4

1 Answers1

0

The url doesn't look right - you'll want to check https://github.com/basecamp/bcx-api/blob/master/sections/messages.md#create-message and https://github.com/basecamp/bcx-api/blob/master/sections/comments.md#create-comment for adding a message or comment.

To add a new message to the project, you'd want

$URL = "https://basecamp.com/***/api/v1/projects/****/messages.json";
Jim Mackenzie
  • 241
  • 1
  • 2
  • I checked the Post message with this url, but it returns the json like this {"status":"400","error":"Bad Request"}. How it can solve? – user3201764 May 15 '14 at 08:40