0

Pretty much title says all, I was able to get the snippet within test = {} to work within salesforce workbench. Would love some guidance on what I am doing wrong as individual "non-bulk" requests work.

test = {
   "allOrNone" : "false",
   "records" : [{
       "attributes" : {"type" : "Sensor_Reading__e"},
       "id__c": "679",
       "power__c": "15.00",
       "temperature__c": "72.6",
       "captureTime__c": "2019-05-20"
    }]
}


headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': 'Bearer '+str(response.json()['access_token'])
}
response = requests.post('https://na50.my.salesforce.com/services/data/v45.0/composite/sobjects', headers=headers,data=test)

print(response.text)

Error:

[{"message":"Unexpected character ('r' (code 114)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:1, column:2]","errorCode":"JSON_PARSER_ERROR"}]

enter image description here

3
  • Could you please post your Python and error message inline, using the {} tool to format your code, rather than posting a screenshot?
    – David Reed
    May 20, 2019 at 18:59
  • Please include code and error messages as text rather than images. The former is searchable and accessible on screen readers, among other things, while the latter is not, making it much more exclusionary.
    – Adrian Larson
    May 20, 2019 at 18:59
  • fixed! please take a look.
    – scarecrow
    May 20, 2019 at 19:00

1 Answer 1

1

You need to convert the object via dumps. As near as I can tell:

import json

...

payload = json.dumps(test)
response = requests.post('https://na50.my.salesforce.com/services/data/v45.0/composite/sobjects', headers=headers,data=payload)

Check out the JSON library for more details.

2
  • I swear to god that did not work for me and now it does, go figure lol. Thanks!
    – scarecrow
    May 20, 2019 at 19:44
  • 1
    @scarecrow It happens to the best of us. Glad I was able to help out!
    – sfdcfox
    May 20, 2019 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .