• Pradheep K
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi,

I'm trying to create a task in SF from Marketo using the REST API. I'm getting the 401 error. Error Message - "HTTP Error 401: Unauthorized access to URL". Basically, I'm sending a request in JSON format and using this endpoint: https://cvent.my.salesforce.com/services/data/v30.0/sobjects/Task

Has anyone faced the same challenge and how did you fix it?

Thanks,
Shashank Sharma
I have a client that is having problems accessing custom SF Rest API.  

Login is successful using oauth2 token (services/oauth2/token) with grant_type = password.  Attempt to access custom REST API using services/apexrest/myRESTInterface with received access_token & instance_url from login response, results in 403 (error code = MUTUAL_AUTHENTICATION_FAILED) from http POST of REST url.

Also, configured a connectedApp (restricted IPs) & profile for the login user.

Help !  I have checked thousands of settings & have performed a ton of googling. And, yep, not a premier customer either.

Here is some code ==>
 1.  Login call:
  URL==>  HTTPS://login.salesforce.com/services/oauth2/token

  Payload ==>  username=XXXXX%40myCompany.org&password=YYYYYYY&grant_type=password&client_id=ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ&client_secret=NNNNNNNNNNN

 2. Custom Rest Call (using access_code & instance_url from login response):
  URL==> HTTPS://NA18.SALESFORCE.COM/services/apexrest/myRESTInterface
  Header ==> Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X-PrettyPrint: 1
  Payload ==>  {"myPayload":["attribute1"]}

Hi,

 

I have successfully integrated Twilio with salesforce, contacts can call the twilio number and get routed accordingly and speak to a company representative, also call and SMS can be made from salesforce.

 

What I am looking for is when an outside caller calls the twilio number a small popup window should display the contact's details.

 

How can I achieve this functionality? 

 

Architecture:

================

 

Triggering point: Visualforce Page, tied to a Apex Class.

The caller is requested to press "1" to speak to someone, right now the owner of the record is automatically called. (at this point the pop up window should be displayed. which is my requirement)

 

Page 1 is first invoked which is linked to a controller and the caller is greeted with name and directed to press a 1, when the caller presses 1 it is directed to Page 2 which automatically calls the owner of the contact record.

 

Page 1:

 

<apex:page controller="KVTwilioController" showheader="false" contentType="text/xml" 
  >{! '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' }
    <Response>
        <Say>Hello {!name}</Say>
        <Say>Welcome to Neuberger Berman.</Say>

        <Gather  numDigits="1" action="KVTwilioHandleKeyPage" method="POST">
          <Say>To speak to a real person, press 1. Press any other key to start over.</Say>
        </Gather>

    </Response>
</apex:page>

 Controller controlling Page 1:

public class KVTwilioController {
 
  public KVTwilioController() {}
 
  /* return TwiML */
  public String getName() {
    // if the caller is known, then greet them by name
    // otherwise, consider them just another monkey
    String name = 'Hi';
    
    String fromPhone = ApexPages.currentPage().getParameters().get('From');
    if (fromPhone!=null) {
    
        System.debug('~~~~~~~~ KVTwilioController : fromPhone : ' + fromPhone);
    
      // remove the country prefix for Phone field search
      if (fromPhone.startsWith('+1'))
        fromPhone = fromPhone.substring(2);
    
      // search Lead and Contact phone number fields
      List<List<SObject>> results = [FIND :fromPhone IN Phone FIELDS
          RETURNING Contact(FirstName, LastName), Lead(FirstName, LastName)
          LIMIT 1];
    
      // extract the name if there’s a match
      if (!results[0].isEmpty()) {
        Contact r = (Contact)results[0][0];
        name = r.firstName + ' ' + r.lastName;
        
        System.debug('~~~~~~~~ KVTwilioController : Contact Name : ' + name);
        
      } else if (!results[1].isEmpty()) {
        Lead r = (Lead)results[1][0];
        name = r.firstName + ' ' + r.lastName;
        
        System.debug('~~~~~~~~ KVTwilioController : Lead Name : ' + name);
        
      }
    }
    return name;
  }
  
  // if the caller pressed anything but 1 send them back
    public PageReference getHandleUserInput() {
        PageReference p = new PageReference('/apex/KVTwilioHandleKeyPage');
        if (ApexPages.currentPage().getParameters().get('Digits') == '1'){
        }  
        return p;
    }
  
  
}

 Page 2:

<apex:page controller="KVTwilioHandleKeyController" showheader="false" contentType="text/xml"
  >{! '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' }
    <Response>
        <Dial>{!dialNumber}</Dial>
        <Gather action="KVPopUpPage" />
        <Say>The call failed or the remote party hung up. Goodbye.</Say>
    </Response>
</apex:page>

 Controller controlling page 2

public class KVTwilioHandleKeyController
{
  public String getDialNumber() {
    // if the caller is known, then find their owner's phone number
    String dialNumber;
    
    String fromPhone = ApexPages.currentPage().getParameters().get('From');
    if (fromPhone!=null) {
      // remove the country prefix for Phone field search
      if (fromPhone.startsWith('+1'))
        fromPhone = fromPhone.substring(2);
    
      // search Lead and Contact phone number fields
      List<List<SObject>> results = [FIND :fromPhone IN Phone FIELDS
          RETURNING Contact(Owner.Phone), Lead(Owner.Phone)
          LIMIT 1];
    
      // extract the owner phone if there’s a match
      if (!results[0].isEmpty()) {
        Contact r = (Contact)results[0][0];
        if (r.owner!=null && r.owner.phone!=null)
          dialNumber = r.owner.phone;
      } else if (!results[1].isEmpty()) {
        Lead r = (Lead)results[1][0];
        if (r.owner!=null && r.owner.phone!=null)
          dialNumber = r.owner.phone;
      }
    }
    return dialNumber;
  }
 
  // if the caller pressed anything but 1 send them back
  public String redirect() {
    if (ApexPages.currentPage().getParameters().get('Digits') != '1')
      return '/KVTwilioPage';
    return null;
  }  

}