I am trying to set data from an Azure Service Bus to an instance of Salesforce using the Bulk API 2.0 and and REST (because who really wants to deal with SOAP?).
I am currently struggling "simply" to get a jobId
which I can hang the rest of this process on.
This is my method so-far:
private string CreateJob(String sObjectType, AuthenticationToken token, IConfigurationRoot config) {
this.log.LogInformation($"####### TOKEN: {token.Access_token}");
this.log.LogInformation($"####### URL: {config["SalesforceBulkApi2Endpoint"]}jobs/ingest");
this.log.LogInformation($"####### BODY: {JsonConvert.SerializeObject(new JobRequestBody("Account"))}");
IRestRequest request = new RestRequest($"{config["SalesforceBulkApi2Endpoint"]}jobs/ingest")
.AddHeader("Authorization", $"Bearer {token.Access_token}")
.AddHeader("Accept", "application/json")
.AddParameter("application/json", JsonConvert.SerializeObject(new JobRequestBody(sObjectType)), ParameterType.RequestBody);
IRestResponse response = new RestClient(config["SalesforceInstanceBaseUrl"])
.Post(request);
this.log.LogInformation("####### response" + response);
this.log.LogInformation("####### response.Content " + response.Content);
if (!response.IsSuccessful) {
throw new SaleforceServiceException("Cannot create job", response);
}
return null;
}
In my local.settings.json (cause I am still working locally), I have the following relevant values:
"SalesforceLoginEndpoint": "https://test.salesforce.com/services/oauth2/token",
"SalesforceInstanceBaseUrl": "https://enpal--bmk84.lightning.force.com/",
"SalesforceBulkApi2Endpoint": "/services/data/v48.0/",
...as well as values for creating the token which seems to be working.
However the above code always fails throwing an exception, from which I see: "[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]"
Any idea how to fix this?