Trying to post a file

59 views
Skip to first unread message

Gregory Shaw

unread,
Feb 6, 2014, 7:04:55 AM2/6/14
to assembla...@googlegroups.com
Hello

I have used the following curl statement to post a file to assembla:

$ curl -H "X-Api-key: e14cf558e7" -H "X-Api-secret: 5b6aac6df0d639c1dc" -F "document[file]=c:/Users/ci1gsx/Downloads/AcYear.pdf" -H "Content-Type multipart/form-data" https://api.assembla.com/v1/spaces/civil-technical/documents.json

and I get this error. 

HTTP/1.1 100 Continue

HTTP/1.1 404 Not Found
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Thu, 06 Feb 2014 11:56:12 GMT
Server: nginx/0.7.67
Set-Cookie: assembla_sso=A38B3EFE137903AA0DA5E9F6E3811639%3AC8F4AAF405B4FCB5A5F60E1F5255DB1CE49323F6438FD953895FB30C2B51F780A3CD7B7B1DCB6165B3299F1ABCAE50CC; domain=.assembla.com; path=/; expires=Thu, 06-Feb-2014 23:56:12 GMT
Set-Cookie: _breakout_session=25f2dabba111d97cc336bd79586170d9; domain=.assembla.com; path=/; expires=Thu, 06-Feb-2014 14:56:12 GMT; secure; HttpOnly
Status: 404 Not Found
X-Powered-By: Phusion Passenger 4.0.25
X-Rack-Cache: invalidate, pass
X-Request-Id: 6c028abce83cc55cb2b63ca391d4f319
X-Runtime: 0.072116
X-UA-Compatible: IE=Edge,chrome=1
Content-Length: 43

{"error":"Tool not found for this project"}

Not sure what is wrong.

Any assistance would be grateful.

Thanks
Greg

Stanislav Kolotinskiy

unread,
Feb 6, 2014, 7:24:25 AM2/6/14
to assembla...@googlegroups.com
Hi Gregory,

as http://api-doc.assembla.com/content/api_reference.html states, you
have to have a Files tool in your project before you can use Documents
API. From what I'm seeing, your project doesn't have a Files tool.
Please add one, then try again.

Regards,
Stanislav
> --
> You received this message because you are subscribed to the Google
> Groups "Assembla API Development" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to assembla-api-d...@googlegroups.com.
> To post to this group, send email to assembla...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Gregory Shaw

unread,
Feb 6, 2014, 7:47:09 AM2/6/14
to assembla...@googlegroups.com
Hello Stanislav

I'm sorry about that I should have read that.

The Curl statement now works, but I'm wanting it to upload via php. Below is my code:

$headers    = array('X-Api-Key: e14cf558e8d7','X-Api-Secret: 5b6aac6df0d639c14c46ddc','document[file]=@c:/Users/ci1gsx/Downloads/AcYear.pdf','Content-type: application/json','Content-Type multipart/form-data');

$p = "{\"ticket\":{\"summary\":\"".$create."\",\"custom_fields\":{\"Points\":\"".$points."\",\"CurrOwner\":\"".$owner."\",\"Project\":\"".$project."\"}}}"; (this line works used for ticket creation)

$ch = curl_init();
echo($ch);
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $p,
    CURLOPT_SSL_VERIFYPEER => false
));
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print("HTTP status: " . $http_status);

I get a HTTP 422 error. I know the above code works because I've used it to create tickets but not sure what I need to alter to upload files with it.

Thanks for helping Stanislav

Greg

Stanislav Kolotinskiy

unread,
Feb 7, 2014, 5:10:51 AM2/7/14
to assembla...@googlegroups.com
Hi Gregory,

from what I'm seeing, you're sending a wrong body - your request body should contain "document" namespace. Please check API documentation for more details.

Regards,
Stanislav
--

Gregory Shaw

unread,
Feb 7, 2014, 5:22:04 AM2/7/14
to assembla...@googlegroups.com
Hello Stanislav

I've changed it to this:

$headers    = array('X-Api-Key: e14cf558e89cb2f662d7','X-Api-Secret: 5b6aac6df0d639c14b7b555d5eb3d02e09c46ddc','Content-Type multipart/form-data',);
$e = realpath('C:/Users/ci1gsx/Downloads/AcYear.pdf');     
$p = 'document[file]=_file_data&document[file]='.'@' .$e ;   
 
 
$ch = curl_init();
echo($ch);
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $p,
    CURLOPT_SSL_VERIFYPEER => false
));
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print("HTTP status: " . $http_status);

and I'm still getting this error:

Resource id #2HTTP status: 422
array (size=1)
  'errors' => 
    array (size=1)
      'name' => 
        array (size=1)
          0 => string 'can't be blank' (length=14)

It would be great in the API reference to have some PHP curl examples so people could understand the syntax for how to do this.

Any more help would be grateful.

Thanks
Greg

On Thursday, 6 February 2014 12:04:55 UTC, Gregory Shaw wrote:

Gregory Shaw

unread,
Feb 7, 2014, 5:34:47 AM2/7/14
to assembla...@googlegroups.com
Hello Stanislav

I read your other post below and it's solved the problem.

Thanks you very much for helping me out.

I do appreciated your efforts and time.

Thanks
Greg

On Thursday, 6 February 2014 12:04:55 UTC, Gregory Shaw wrote:

Stanislav Kolotinskiy

unread,
Feb 7, 2014, 5:38:49 AM2/7/14
to assembla...@googlegroups.com
Hi Gregory,

here's a curl request that worked for me:
 curl -i -H "X-Api-Key: apikeyhere" -H "X-Api-Secret: apisecrethere" -H "Content-Type: multipart/form-data" -F 'document[file]=@/tmp/1.txt' https://api.assembla.com/v1/spaces/spaceidhere/documents.json

Please make sure that curl is correctly setting form fields.

Regards,
Stanislav
--
Reply all
Reply to author
Forward
0 new messages