Hot answers tagged

12

The documentation has a bug in it. Following the documentation, your cURL command would look like this: curl https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=XXXXXX.YYYYY_ZZZZZ" -d "client_secret=000099990000" -d "name@domain.com" -d "password=yourpasswordyoursecuritytoken" It's missing the username= parameter. ...


8

First you need to create a remote Application . Setup -->Create --> App-->Connected Apps-->Fill The Necessary Details --> mention CallBackURL as https://ap1.salesforce.com/services/oauth2/token ,Callback URL in salesforce is nothing but what Salesforce will callback with once the user authorizes access to his/her Salesforce account. Provide callback url as ...


7

cURL is simply a command-line utility, written in C, that runs on a variety of binary platforms (Windows, Linux, Solaris, etc). Arguably, almost anything you can do with cURL you can do with Apex Code. Heroku can't readily determine a request from cURL versus Apex Code versus a telnet connection with the appropriate code copy-pasted from Notepad. What you ...


7

I tried Ashwani's trick. It looks like security removes session id's from logs now. Here's a quick workaround. SYSTEM.DEBUG('Session Id : ' +Userinfo.getSessionId().reverse()) Then you can just grab it from the log and reverse it again.


7

I have seen client id's and some passwords which need to be urlencoded/escaped to work well with curl. Maybe you should try the --data-urlencode option (source: https://stackoverflow.com/questions/10060093/special-characters-like-and-in-curl-post-data ) Example usage would be: curl -v https://test.salesforce.com/services/oauth2/token -d "grant_type=...


6

Instead of delegating to a human for credentials, you can use the Username-Password flow (where you securely store the credentials and a security token) - here's an example: Authenticate with credentials stored on your server (the response will be JSON, not frontdoor.jsp) $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => ...


5

My username had a + in it, which wasn't correctly encoded. -d "username=ray+1@gmail.com" needed to be -d "username=ray%2B1@gmail.com"


5

Login to salesforce organization Open developer console > execute anonymous Type following line. This gives current logged in user's session ID.: SYSTEM.DEBUG('Session Id : ' +Userinfo.getSessionId()); Above is the non-dynamic way to get session id. As you are just testing with cURL so this way will save your time. But i will recommend to read REST API ...


5

This is a feature of OAuth, and is working as designed. A connected app clientId and secret can be used to connect to any org provided you go through oauth flow and enter username and password (or alternatively provide them using the username-password flow). Note that you will still need username and password for the PROD and cannot access anything allowed ...


4

You may want to look at httpie It's CURL-like, open source, multi-platform (DOS, Win, Mac), it offers several prettify options - format, color etc.


4

I strongly suspect that something is going sideways because you're not properly escaping the non-safe URL characters (like \ and [); in a URL, they must be in a certain style known as "percent encoding". Here's how I'd approach your problem: ApexPages.PageReference ref = new ApexPages.PageReference('https://api.example.com/output'); ref.getParameters().put('...


3

you are giving the Callback url befor the user is authorised to access his her salesforce account. Callback URL in salesforce is nothing but what Salesforce will callback with once the user authorizes access to his/her Salesforce account. Provide callback url as https://ap1.salesforce.com/services/oauth2/token so giving the callabck url after the user is ...


3

It looks like the problem could be that you were using an access token instead of a session id. I just got it to work by logging in through the enterprise api and using that session id for sid= in the header. the command I used to log in and get the session id: $ curl https://login.salesforce.com/services/Soap/c/33.0 -H 'Content-Type: text/xml; charset=UTF-...


3

In the simplest sense, yes you can. You can use the example verbatim from the HTTP classes documentation to send a GET request and return the HTML source as a string. public class HttpCalloutSample { // Pass in the endpoint to be used using the string url public String getCalloutResponseContents(String url) { // Instantiate a new http object ...


3

When you invoke curl from the command line, you have to escape any double quotes that you include within any quoted string. The escaped quotes are interpreted by your shell (probably bash), not by curl itself or by your remote service. Your "real" outgoing JSON shouldn't include any backslashes. You should only have those present when you're embedding a ...


3

It'd probably be best if you started as a String array: // ... String[] payloadParts = new String[0]; String[] toBindings = new String[] { '{"address": "+18005551212", "binding_type": "sms"}', '{"address":"+18005551233","binding_type":"sms"}' }; payloadParts.add('Body='+EncodingUtil.urlEncode(body,'utf-8')); for(String toBinding: toBindings) { ...


3

I think you'll be better off using JWT for oAuth. It's more predictable behavior. Here is a PHP github library that I've used that has a lot of the code - https://github.com/adhocore/php-jwt To read up on the JWT flow, check this out: https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=0


2

That won't work, because login sends back a page that JavaScript redirects to the start URL, so curl will just see this html file and not know what to do with it. Instead, assuming you received a sid cookie from the first cookie command, your next step would be to call your instance server directly with the correct URL. This should allow the file to download ...


2

Chris, getting the data into a Visualforce page is pretty straightforward. All you need is an Apex controller. The sample Visualforce page and Apex controller below illustrates how you can pull the array you defined into a page to be rendered. OpportunitiesIndex.page <apex:page controller="OpportunitiesController"> <!-- The value attribute ...


2

Try this ;) req.setBody('{"vendorName":"testVendor"}'); Send valid JSON data to server; As server also saying 400 Bad Request Error;


2

I am hoping that you are using Force.com PHP SDK. You can directly call attachment SOAP API with following code. $url = "$instance_url/services/data/v20.0/sobjects/Attachment/"; $accId='00435DAFDF3'; //frmResume is <inputfile name if(isset($_FILES['frmResume']) && $_FILES['frmResume']!=null) { $...


2

I was using the incorrect Content-type ... It should be application/json


2

Is there any other way to fix this? In theory, yes. You can go to Setup > Security Controls > Certificate and Key Management, upload some new certificates, and assign them to your Site via custom URLs. You'll probably need your own domain or subdomain name to make this work correctly. I don't have a production org I can experiment with, so you'll want to ...


2

flow expect input parameters while calling through API so you need to pass blank input array if you are not passing any value. Update your body with following json { "inputs": [ {} ] } So your code will look like this $url = "https://myInstance.salesforce.com/services/data/v40.0/actions/custom/flow/EndCourse_and_Semester_Notification"; $headers = ...


2

A request bin service can be helpful in showing exactly what curl generates for the outbound body content. The curl manpage is also helpful: --data-urlencode (HTTP) This posts data, similar to the other -d, --data options with the exception that this performs URL-encoding. In this case, using your command line, the generated request body is Body=...


1

A good place to start would be to look at the documentation on HttpRequest. Most everything should map fairly intuitively from cURL. For example... POST, GET, PUT, etc... are Http methods, so use setMethod(String method) you'd pass 'https://thingspace.verizon.com...' into setEndpoint(String endpoint) each individual header is set by using setHeader(String ...


1

Your Apex is combining Basic Auth and OAuth, you are confusing yourself... that approach won't work. The OAuth dance is NOT the same thing as Basic Authentication. This is "basic-auth-ish" and won't work with OAuth bearer token. You don't need either of these lines: Blob headerValue = Blob.valueOf('7512d7f8-2706-4dcd-a288-af482fb728ca'); String ...


1

Try to add this line in your code. req.setBody('vendorName=testVendor'); Instead of: req.setBody('vendorName:testVendor');


1

You are passing a JSON which is not constructed properly. You have a trailing comma , at the end of last key-value pair, so JSON parse assumes you are going to declare few more variables. But since you abruptly close it with } it fails in parsing it. Assuming by the error message you have error at Line:25 column 6 your json string should look something ...


1

The only way I know of to validate a refresh token is to attempt to use it to get an access token - if the attempt fails, the refresh token is no good.


Only top voted, non community-wiki answers of a minimum length are eligible