RESTMessageV2 Issue : request endpoint url is forced change to Lowercase

Suhyeon Lee
Tera Expert
This issue caused 400 errors
 
My test code is as follows : 
 
sm = new sn_ws.RESTMessageV2('Wrike API', 'CONTACTS');
sm.setHttpMethod("get");

 

response = sm.execute();
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
gs.info(responseBody);
 
Result Error Messages :
Error:
	Error Code: 1
	Error Message: Method failed: (/api/v4/users/awe2g4q/) with code: 400

*** Script: Method failed: (/api/v4/users/awe2g4q/) with code: 400
 
2 ACCEPTED SOLUTIONS

Akash4
Kilo Sage

Hi Suhyeon,

The error is HTTP 400 Bad Request, happens as the URL is misinterpreted/missing data. Did you check if Content-Type, Authorization as headers?

I see as per Wrike API Docs - , "Authorization: bearer eyJ0dCI6InAiLCJhbGciOiJIUzI1NiIsInR2IjoiMSJ9.eyJkIjoie1wiYVwiOjIyMzMwMDEzLFwiaVwiOjIyLFwiY1wiOjEwMDUsXCJ2XCI6XCJcIixcInVcIjozNyxcInJcIjpcIlVTXCIsXCJzXCI6W1wiTlwiLFwiSVwiLFwiV1wiLFwiRlwiLFwiS1wiLFwiVVwiLFwiQ1wiLFwiQVwiLFwiTFwiLFwiUFwiLFwiQlwiLFwiRFwiXSxcInpcIjpbXSxcInRcIjoxNzI2NTYzMDgxMDAwfSIsImV4cCI6MTcyNjU2MzA4MSwiaWF0IjoxNzI2NTU5NDgxfQ.7eR6FV8Vank0NvbVQ1Zx5x8YIPKZMlXUKsW7lGLva2k' is available for Header usage.

Secondly, incase you are getting user information using GET, try sm.setStringParameterNoEscape('user_id', 'awe2g4q');

 

var sm = new sn_ws.RESTMessageV2('Wrike API', 'CONTACTS'); 
//assuming CONTACTS is GET method and Wrike API can have the parent URL <'https://wrike.com/API/V4/USERS'>
sm.setStringParameterNoEscape('user_id', 'awe2g4q'); // User ID
var response = sm.execute();
var responseBody = response.getBody();
var status = response.getStatusCode();
gs.info(responseBody);

 

 

View solution in original post

Shaqeel
Mega Sage

Hi @Suhyeon Lee 

 

Here's a revised version of your code:

 

var sm = new sn_ws.RESTMessageV2('Wrike API', 'CONTACTS');
sm.setHttpMethod('GET');
sm.setEndpoint('https://www.wrike.com/api/v4/contacts/AWE2G4Q'); 

sm.setRequestHeader('Authorization', 'Bearer your_api_key_or_oauth_token');

var response = sm.execute();
var responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
var status = response.getStatusCode();

gs.info('Status Code: ' + status);
gs.info('Response Body: ' + responseBody);

 

 

If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

 

Regards

Shaqeel

 

View solution in original post

3 REPLIES 3

Akash4
Kilo Sage

Hi Suhyeon,

The error is HTTP 400 Bad Request, happens as the URL is misinterpreted/missing data. Did you check if Content-Type, Authorization as headers?

I see as per Wrike API Docs - , "Authorization: bearer eyJ0dCI6InAiLCJhbGciOiJIUzI1NiIsInR2IjoiMSJ9.eyJkIjoie1wiYVwiOjIyMzMwMDEzLFwiaVwiOjIyLFwiY1wiOjEwMDUsXCJ2XCI6XCJcIixcInVcIjozNyxcInJcIjpcIlVTXCIsXCJzXCI6W1wiTlwiLFwiSVwiLFwiV1wiLFwiRlwiLFwiS1wiLFwiVVwiLFwiQ1wiLFwiQVwiLFwiTFwiLFwiUFwiLFwiQlwiLFwiRFwiXSxcInpcIjpbXSxcInRcIjoxNzI2NTYzMDgxMDAwfSIsImV4cCI6MTcyNjU2MzA4MSwiaWF0IjoxNzI2NTU5NDgxfQ.7eR6FV8Vank0NvbVQ1Zx5x8YIPKZMlXUKsW7lGLva2k' is available for Header usage.

Secondly, incase you are getting user information using GET, try sm.setStringParameterNoEscape('user_id', 'awe2g4q');

 

var sm = new sn_ws.RESTMessageV2('Wrike API', 'CONTACTS'); 
//assuming CONTACTS is GET method and Wrike API can have the parent URL <'https://wrike.com/API/V4/USERS'>
sm.setStringParameterNoEscape('user_id', 'awe2g4q'); // User ID
var response = sm.execute();
var responseBody = response.getBody();
var status = response.getStatusCode();
gs.info(responseBody);

 

 

Shaqeel
Mega Sage

Hi @Suhyeon Lee 

 

Here's a revised version of your code:

 

var sm = new sn_ws.RESTMessageV2('Wrike API', 'CONTACTS');
sm.setHttpMethod('GET');
sm.setEndpoint('https://www.wrike.com/api/v4/contacts/AWE2G4Q'); 

sm.setRequestHeader('Authorization', 'Bearer your_api_key_or_oauth_token');

var response = sm.execute();
var responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
var status = response.getStatusCode();

gs.info('Status Code: ' + status);
gs.info('Response Body: ' + responseBody);

 

 

If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

 

Regards

Shaqeel

 

Hi @Suhyeon Lee 

 

Thanks a lot. 🙂