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. ...


9

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.


8

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 ...


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

The route listed in this question is unsupported. It should not be used in production environments. This route may stop working or become unavailable at any time with no notice.


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 => ...


6

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 ...


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

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

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

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

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


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

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

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

I found the answer, I had the wrong syntax for setting the curl headers. I tried to pass the values as an associative array, but the correct way is like this: curl_setopt($ci, CURLOPT_HTTPHEADER, array( 'Accept: application/json', 'Authorization:' . $sf_auth, 'X-PrettyPrint:1' ));


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

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=Test%...


2

I finally found that the problem is related to Bash which interprets the '!' char in a specific way (command history if I understood well). I found about the same question on the Unix stackexchange and 1 of the advice was to deactivate the command history with the command "set +H". It works fine and you don't even have to escape the '!' character. ...


2

Setting +H before the command should fix it.


2

The following api can get you customer subscription HttpRequest req1 = new HttpRequest(); req1.setMethod('GET'); String customerId='cus_HJ3f4cSLOxY9a6'; string endpoint='https://api.stripe.com/v1/customers/'+customerId+'/subscriptions'; req1.setEndpoint(endpoint); String username = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'; Blob headerValue = Blob.valueOf(...


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