How to use HTTP Post with API (File upload) - error 400 bad request

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

How to use HTTP Post with API (File upload) - error 400 bad request

Hello!

I think I managed to go through the CORS problems I've been having for a quite some time.

I'm trying to use Angular's HttpClient. I've builed simple xml file using xmlBuilder in the typescript - and I would like to post it to the desired subfolder using Alfresco API. I've been trying to use that kind of snippet to post it but I'm getting error 400 with a bad request as a status - I think I'm missing certain headers or something like that in this http post but I'm not sure what exactly and how to do it to be able to post xml file. Moreover - I am not sure how to set a certain folder as a target folder for the newly posted file.

import { HttpClient } from '@angular/common/http';
private http: HttpClient
--------------------------------------------------------------------------------------------------
this.http.post('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-
/children?alf_ticket=<ticket>', xml).subscribe(
data => {
console.log("POST Request is successful ", data);
},
error => {

console.log("Error", error);

}

);
2 Replies
Highlighted
Alfresco Employee

Re: How to use HTTP Post with API (File upload) - error 400 bad request

Are you using ADF? 

Highlighted
Active Member

Re: How to use HTTP Post with API (File upload) - error 400 bad request

Yes, I am using ADF but I've managed to solve the problem with this: https://community.alfresco.com/community/ecm/blog/2016/10/24/v1-rest-api-part-3-creating-nodes  - long story short I've been missing an actual body defining name or path, so the snippet looks more or less like that ('node.name' is folder name, where an actual document is going to be put):

this.http.post('http://localhost:8080
/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-/children?alf_ticket=<ticket>',
{"name": doc_nr + ".xml", "nodeType": "cm:content", "relativePath": "/" + node.name })
.subscribe(
data => {

console.log("POST Request is successful ", data);
},
error => {

console.log("Error", error);

}

);