You need to sign in to do that
Don't have an account?
Andy Morton 14
Create custom record with HTTP REST API Powershell not working
Hello all,
I've been working on some API integration between Salesforce and SQL using Powershell.
So far I've managed to get the majority working with querying Salesforce for some record details, grabbing information from SQL and inserting the SQL data into the Salesforce records.
However, I'm having some trouble trying to get it to create a new record.
We have a custom object (Usage_Billings__c) which the SQL data is put into. Inserting this into existing records is fine but if I try to create a new record it fails with error "Unexpected character ('P' (code 80)): was expecting comma to separate OBJECT entries at [line:3, column:33]","errorCode":"JSON_PARSER_ERROR"
I'm fairly new to API integrations and haven't had much luck with finding a solution online (according to some posts, what I'm doing should work fine).
My Script:
(I've omitted our SF connection section which works fine as can gather the information fine as well as our sandbox URL)
All help appreciated.
Andy
I've been working on some API integration between Salesforce and SQL using Powershell.
So far I've managed to get the majority working with querying Salesforce for some record details, grabbing information from SQL and inserting the SQL data into the Salesforce records.
However, I'm having some trouble trying to get it to create a new record.
We have a custom object (Usage_Billings__c) which the SQL data is put into. Inserting this into existing records is fine but if I try to create a new record it fails with error "Unexpected character ('P' (code 80)): was expecting comma to separate OBJECT entries at [line:3, column:33]","errorCode":"JSON_PARSER_ERROR"
I'm fairly new to API integrations and haven't had much luck with finding a solution online (according to some posts, what I'm doing should work fine).
My Script:
(I've omitted our SF connection section which works fine as can gather the information fine as well as our sandbox URL)
$GUID = "810Pu000001MruoIAC" $getContracturl = "https://MYSANDBOX.my.salesforce.com/services/data/v57.0/query?q=SELECT+FIELDS(ALL)+FROM+servicecontract+WHERE+id+=+'$GUID'+LIMIT+50" $getContractResponse = Invoke-RestMethod -Uri $getContracturl -Method 'Get' -Headers $headers -TimeoutSec 0.03 $getContractResponse | ConvertTo-Json -Depth 10 $accountid = $getContractResponse.records.accountid $dat_size = "150" $lic_365 = "1" $lic_google = "1" $createUrl = "https://MYSANDBOX.my.salesforce.com/services/data/v57.0/sobjects/Usage_Billing__c" $requestbody =@" { "Service_Contract__c" : $GUID, "Stor__c" : $dat_size, "X365_Users__c" : $lic_365, "G_Users__c" : $lic_google } "@ Write-Host $requestbody $createBilling = Invoke-RestMethod -Uri $createUrl -Method 'Post' -Headers $headers -Body $requestbody -TimeoutSec 0.03 $createBilling | ConvertTo-JSONAnyone able to point me in the right direction?
All help appreciated.
Andy
"Service_Contract__c" : "$GUID",
All working now - will leave this here in case anyone else comes across same issue (shows that something simple can waste loads of time :) )
All Answers
{
"Service_Contract__c" : 810Pu000001MruoIAC,
"Stor__c" : 150,
"X365_Users__c" : 1,
"G_Users__c" : 1
}
"Service_Contract__c" : "$GUID",
All working now - will leave this here in case anyone else comes across same issue (shows that something simple can waste loads of time :) )