Post

2 followers Follow
0
Avatar

Can't request to getUploadUrl

I am trying to use the getUploadUrl endpoint but it keeps returning the documentation page instead of actually working. I tried in so many ways... I am using Apex (Salesforce):

Http h = new Http(); 
HttpRequest req = new HttpRequest(); 
req.setEndpoint('https://api.clarizen.com/V2.0/services/files/getUploadUrl'); 
req.setMethod('GET'); 
req.setHeader('Content-Type', 'application/json;charset=UTF-8'); 
req.setHeader('Authorization', sessionId); 
HttpResponse response = h.send(req);

I tried adding a body but it returns a 404 error. I tested another Content-Types as well and nothing. What am I doing wrong?

And there is no parameter mentioned in API Documentation.

Luiz Fellipe de Oliveira Almeida Answered

Please sign in to leave a comment.

5 comments

0
Avatar

Hello Luiz,

I'm not sure if this can have a negative effect, but I think you should not specify the content type. Also, did you include the Session keyword in the sessionId (example: "Session somesessionID")? Maybe something like this would work?

Http h = new Http(); 
HttpRequest req = new HttpRequest(); 
req.setEndpoint('https://api.clarizen.com/V2.0/services/files/getUploadUrl'); 
req.setMethod('GET'); 
req.setHeader('Authorization', 'Session' + ' ' + sessionId); 
HttpResponse response = h.send(req);

I hope this helps.

Roland

Roland Pumputis 0 votes
Comment actions Permalink
0
Avatar

Hello Roland, thanks for your response!

Yes, my sessionId already includes "Session " in the beginning. It is not the first request that I use in Apex and all works fine, just this endpoint that I am having problems with. I tested removing the Content-Type as well and there is no change... But thanks anyway!

Luiz Fellipe de Oliveira Almeida 0 votes
Comment actions Permalink
0
Avatar

Hello Luiz,

I've just tested the following on Postman and it worked:

Example JS code:

var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});

xhr.open("GET", "https://api.clarizen.com/V2.0/services/files/GetUploadUrl");
xhr.setRequestHeader("Authorization", "Session c7810842-62db-4c7e-bce7-472***********************************");

xhr.send(data);

I hope this helps.

Roland

Roland Pumputis 0 votes
Comment actions Permalink
0
Avatar

Hello Roland!

I tested your ideia and it didn't work in Apex (Salesforce). I really don't know what is going on. I already use Clarizen API v2 with other endpoints and everything works fine. My code to test the getUploadUrl (sessionId includes "Session " in the beggining):

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.clarizen.com/V2.0/services/files/GetUploadUrl');
req.setMethod('GET');
req.setHeader('Authorization', sessionId);
HttpResponse response = h.send(req);

System.debug(response.getBody());

This debug shows the documentation page and no errors... I tested it on Postman as well and it works there. Maybe the problem is Salesforce itself. But thank you anyway, again!!

Luiz Fellipe de Oliveira Almeida 0 votes
Comment actions Permalink
0
Avatar

Hello Luiz,

My suggestion is to contact Salesforce support and demonstrate that an API call works over Postman but not when using Apex.

Thank you,

Roland

Roland Pumputis 0 votes
Comment actions Permalink