[SalesForce] Retrieving User from Salesforce failing with 411 error

I'm attempting to retrieve a custom object record by one of it's unique fields using the built in api. For this specific call, my request is is:

path: `/services/data/v43.0/sobjects/YTPStudent__c/drupalId__c/39111`
method: GET
headers:
  Authorization: 8248...3483
  Content-Type: application/json

When I do this on Postman, it works fine. I get the proper response. However, when I make the exact same call via Drupal., it's failing with this html:

error

And the response body is this:

Code: 411
Error: length required

Is the 411 a false error? It doesn't make much sense why it works for one platform but not another….

Best Answer

Thank You for answered your own question. It works perfectly!

Turns out, this occurred because Salesforce freaks out and gives a falsy error when Content-Length is provided in a GET request. Drupal was automatically adding Content-Length to a request if data was sent (not sure how data got sent in the request). So, on Salesforce's API, if you provide Content-Length in the headers on a GET request, it will throw a 411: Content-Length Required error. Nicely done Salesforce – BlondeSwan Jan 17 '20 at 1:00

Related Topic