Friday, 7 August 2015

Webservice RestCall using POSTMAN



Steps to hit webservice from POSTMAN REST Client
  1. Rest Service Class in Salesforce
@RestResource(urlMapping='/UpdateMerchantAssetStatus/*')
    global with sharing class RESTMerchantAssetController{   
        @HttpPost
        global static ResponseHandler UpdateMerchantAssetStatus(String MerchantAssetId, String Status,
                        String OrgId,String ThumbName,String FileName,String DisplayName,
                        String FileHeight, String FileWidth, String FileURL){                     
        ResponseHandler response = new ResponseHandler();
        Merchant_Asset__c objMerchantAsset=new Merchant_Asset__c(id=MerchantAssetId,Status__c=Status,
                              Salesforce_Org_ID__c=OrgId,File_Width__c=FileWidth,                                                           
                              File_URL__c=FileURL,File_Name__c=FileName,File_Height__c=FileHeight,                                                           
                              Display_Name__c=DisplayName);
            System.debug('MerchantAssetId: '+MerchantAssetId);
            System.debug('Status '+Status);
            try{
                update objMerchantAsset;
                sobject objAsset=new Merchant_Asset__c();
                objAsset=(sobject)objMerchantAsset;
                response.Data = objAsset;
                response.Status = 'Success';              
            }catch(Exception exp){
                response.Status = 'Fail';
            }
            return response;
        }  
}

2.  global class ResponseHandler {

    public String Status {get; set;}

    public sObject Data {get;set;}    

}
 
  1. Launch POSTMAN and click on OAuth 2.0 tab and then click on ‘Get Access Token’ button:
  1. Fill following required details as below: Client Id & Client secret can be generated by creating a connected App in salesforce
c.       Client ID: 3MVG9zZht._ZaMukxu8cN6FHUteykMdv8YNVOeMm1oUTM1hSuZLZT.mPs628tZLkX2RsXZgJ5sFWk9t2lQOS0
d.      Client Secret: 1837523717317747721
Click on ‘Get access token’ button.
  1. Fill the Salesforce User name and password and click on ‘Log in to Salesforce’ button

  1. if everything is correct, you will get success screen with access token details:
  1. save the token and now put the details as below:
b.      Select method as ‘POST’
c.       Put the details in header as below:
Authorization: OAuth + Access Token[as received in step 4]
Content-Type: application/json


d.      Put the request in json format:
{
"MerchantAssetId" : "a2yq00000008U0t",
"Status" : "Approved",
"OrgId" : "00Dq0000000AlSW",
"FileWidth" : "250",
"FileHeight" : "250",
"FileURL" : "www.google.com",
"FileName" : "TestFile2",
"DisplayName" : "TestFile2"
}
e.      Click on ‘Send’ button
  1. If everything is correct there will be success response as below:


No comments:

Post a Comment