I am working with a sandbox account trying to make calls to the Bulk API. This code has worked before but right now I am getting this error back when I attempt to create a new Job.

```
<?xml version="1.0" encoding="UTF-8"?><error
   xmlns="http://www.force.com/2009/06/asyncapi/dataload">
 <exceptionCode>InvalidSessionId</exceptionCode>
 <exceptionMessage>Invalid session id</exceptionMessage>
</error>

```

I am passing the session ID (from the SOAP API's `login` method) in the `X-SFDC-Session` header. The User Session Information section in the account's Setup area shows the sessions created by this script. You can see the session in this redacted screenshot. It is the one in light blue.

[![enter image description here](https://i.stack.imgur.com/4Ggz2.png)](https://i.stack.imgur.com/4Ggz2.png)

I am not sure where to look next to find the source of this problem. I moved my code into a standalone script and simplified it as much as possible:

```
#!/usr/bin/php
<?php

$wsdl = 'sandbox.partner.wsdl.xml';
$soap = new SoapClient($wsdl);

$username  = 'myusername';
$password  = 'mypassword';
$password .= 'mytoken';

$loginResult = $soap->login([
    'username' => $username,
    'password' => $password
]);

$sessionId = $loginResult->result->sessionId;

$host = parse_url($loginResult->result->serverUrl, PHP_URL_HOST);
$url = "https://$host/services/async/27.0/job";

$headers = [
    "X-SFDC-Session: $sessionId",
];

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_VERBOSE => 1,
    CURLOPT_POST => 1,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
    CURLOPT_HTTPHEADER => $headers,
]);

$result = curl_exec($curl);

var_dump($result);

```

The result is always the error above with a `400 Bad Request` response code. The session ID variable is populated with a valid looking value.

Update
------

I ran this script from a AWS server and it works! My local IP (from where it is not working) is whitelisted in Salesforce so I'm not sure what the difference is to the API and why it rejects requests from my local IP.