• Jason Adler 14
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
The below is the code in my callout class with keys left out. I have tested in postman and the JSON quote like: '{"User": {"account_expires" : "2022-11-18"}}' works perfectly to update when making the call. However, when I run from Salesforce using this callout class, in debug logs, I can see debug statement looks like: 
11:01:27.11 (14669480)|USER_DEBUG|[29]|DEBUG|{"User": {"account_expires" : "2022-11-18"}}
but it seems variable assignment actually looks lke:
11:01:27.11 (14553531)|VARIABLE_ASSIGNMENT|[27]|body|"{\"User\": {\"account_e (24 more) ..."
I am thinking I need to deseralize the JSON maybe by using another class but am having trouble with this. At the moment, the response I am receiving is:
11:01:28.153 (1172417713)|CALLOUT_RESPONSE|[34]|System.HttpResponse[Status=Not Found, StatusCode=404]
11:01:28.153 (1172459328)|HEAP_ALLOCATE|[34]|Bytes:90
11:01:28.153 (1172492874)|VARIABLE_SCOPE_BEGIN|[34]|response|System.HttpResponse|true|false
11:01:28.153 (1172567949)|VARIABLE_ASSIGNMENT|[34]|response|"System.HttpResponse[Status=Not Found, StatusCode=404]"|0x733b55dd

Does anyone have an idea to help me edit the below code so that I can receive the successful response?

Thanks!
 
public class LearnUponCalloutClass {
    	
    	 @future(callout=true)
   		 public static void makeCallout(Integer UserId) {
            
            //declare variables 
		String username = 'XYZ';
    		String password = 'XYZ';
    		
            //prepare request 
                HTTP h = new HTTP();
                HTTPRequest r = new HTTPRequest();
            
            //set endpoint and authorize 
                r.setEndpoint('https://dphie.learnupon.com/api/v1/users/' + UserId);
            
                Blob headerValue = Blob.valueOf(username + ':' + password);

		String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);

		r.setHeader('Authorization', authorizationHeader);
		r.setMethod('PUT');
          
                String body = '{"User": {"account_expires" : "2022-11-18"}}';
         
		System.debug(body);
            
                r.setBody(body);
             
              //send request
			HTTPResponse response = h.send(r);
      
}

 
The below is the code in my callout class with keys left out. I have tested in postman and the JSON quote like: '{"User": {"account_expires" : "2022-11-18"}}' works perfectly to update when making the call. However, when I run from Salesforce using this callout class, in debug logs, I can see debug statement looks like: 
11:01:27.11 (14669480)|USER_DEBUG|[29]|DEBUG|{"User": {"account_expires" : "2022-11-18"}}
but it seems variable assignment actually looks lke:
11:01:27.11 (14553531)|VARIABLE_ASSIGNMENT|[27]|body|"{\"User\": {\"account_e (24 more) ..."
I am thinking I need to deseralize the JSON maybe by using another class but am having trouble with this. At the moment, the response I am receiving is:
11:01:28.153 (1172417713)|CALLOUT_RESPONSE|[34]|System.HttpResponse[Status=Not Found, StatusCode=404]
11:01:28.153 (1172459328)|HEAP_ALLOCATE|[34]|Bytes:90
11:01:28.153 (1172492874)|VARIABLE_SCOPE_BEGIN|[34]|response|System.HttpResponse|true|false
11:01:28.153 (1172567949)|VARIABLE_ASSIGNMENT|[34]|response|"System.HttpResponse[Status=Not Found, StatusCode=404]"|0x733b55dd

Does anyone have an idea to help me edit the below code so that I can receive the successful response?

Thanks!
 
public class LearnUponCalloutClass {
    	
    	 @future(callout=true)
   		 public static void makeCallout(Integer UserId) {
            
            //declare variables 
		String username = 'XYZ';
    		String password = 'XYZ';
    		
            //prepare request 
                HTTP h = new HTTP();
                HTTPRequest r = new HTTPRequest();
            
            //set endpoint and authorize 
                r.setEndpoint('https://dphie.learnupon.com/api/v1/users/' + UserId);
            
                Blob headerValue = Blob.valueOf(username + ':' + password);

		String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);

		r.setHeader('Authorization', authorizationHeader);
		r.setMethod('PUT');
          
                String body = '{"User": {"account_expires" : "2022-11-18"}}';
         
		System.debug(body);
            
                r.setBody(body);
             
              //send request
			HTTPResponse response = h.send(r);
      
}