• Ganesh test1
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
hi everyone,

I am calling an API with Authtoken in header :
        String resp = 'response : ';
        HttpRequest req = new HttpRequest();
        JSONGenerator gen = JSON.createGenerator(false);
        JSONGenerator gen = JSON.createGenerator(false);
  		String  url = 'http://api.xxxxx.com/xx/xxx/xxx';
        
        	req.setEndpoint(url);
			String reqJSON;
                        gen.writeStartObject();
                        gen.writeStringField ('transaction_id', txnID);
                        gen.writeEndObject();
                        
                        // Get the JSON string.
                        reqJSON = gen.getAsString();        
	        req.setBody(reqJSON);
			req.setEndpoint (url);
	        req.setHeader('Authorization', 'Token xxxxxxxxxxxxxxxxxxxxxxxx');
        
                        req.setMethod ('GET');
                        req.setHeader('Content-Type', 'application/json');
                        req.setHeader('Accept', 'application/json');
                        req.setBody(reqJSON);
                        req.setTimeout(60000);
                      // Get response

        httpResponse res = new http().send(req);
		resp = resp + ' : ' + res.getBody() + ' - '  + res.toString();
	    ApexPages.addMessage(new ApexPages.Message( ApexPages.Severity.info,resp));
but the output i am able to see is this 
response : : - System.HttpResponse[Status=Moved Permanently, StatusCode=301]
​what may be the issue here ,
  • I have checked the API , its working fine on Postman and other platform.
  • I have added the api url on Remote Sites.
Is there any thing else i am missing here ?