I am using this library in C# to make REST calls to SalesForce: https://github.com/developerforce/Force.com-Toolkit-for-NET
I've run into a problem when trying Upsert into Product2. Here is the error message I am getting:
[{"errorCode":"METHOD_NOT_ALLOWED","message":"HTTP Method 'PATCH' not allowed. Allowed are GET,HEAD,POST"}]
The URL it generates:
https://na73.salesforce.com/services/data/v41.0/sobjects/Product2/ProductID__c/# H6 SHORT BARREL NUT
So clearly it wants me to not use upsert. What's weird though is I've been able to upsert on Accounts
and Contacts
as well as others. Even weirder is the methods it says are allowed to use on Product2 don't allow me to update existing products - I can only create new ones via POST. How do I update a product via the API?
Below is the code/payload I am working with just in case I'm doing something wrong...
public async Task<bool> UpsertProduct(SalesForceProduct product, string salesForceField, string salesForceFieldValue)
{
bool Authenticated = await Authenticate();
if (!Authenticated)
{
throw new Exception("[UpsertProduct] Failed to Authenticate");
}
Console.WriteLine("[UpsertProduct] Upserting a potentially new product");
var upsertProductResponse = await forceClient.UpsertExternalAsync(SalesForceProduct.SObjectTypeName, salesForceField, salesForceFieldValue, product);
if (!upsertProductResponse.Success)
{
Console.WriteLine($"[UpsertProduct] An error occurred upserting product {product.ProductID__c}: {upsertProductResponse.Errors.ToString()}");
return false;
}
// The upserts for accounts work this way so I am guessing Product2 is - but I haven't made it this far yet...
product.Id = upsertProductResponse.Id;
if (product.Id == string.Empty)
{
Console.WriteLine($"[UpsertProduct] Updated existing product: {product.ProductID__c}");
}
else
{
Console.WriteLine($"[UpsertProduct] Created new product: {product.Id}");
}
return upsertProductResponse.Success;
}
And how I call the Upsert function:
var hProducts = sql.GetAllProducts();
var convertedProducts = Utilities.STORISProductToSalesForce(hProducts);
SalesForceProduct product = convertedProducts[0];
await sfREST.Authenticate();
await sfREST.UpsertProduct(product, "ProductID__c", product.ProductID__c);
And the payload (product
) I am trying to Upsert:
{"BrandID__c":"<No Value>","CaseSellPrice__c":0.0000,"Class__c":"","Color__c":"","DealCasePrice__c":0.0000,"DepthDimension__c":0.0,"Description2__c":"","GroupID__c":"<No Value>","KitOnly__c":"False","KitStatus__c":"N","Name":"<Unknown>","PieceSellPrice__c":0.0000,"ProductBenefits__c":"","ProductCode":"# H6 SHORT BARREL NUT","ProductID__c":"# H6 SHORT BARREL NUT","ProductTypeID__c":9999,"SpecialOrder__c":true,"Status__c":"","Style__c":"","SuggRetailPrice__c":0.0000,"VendorID__c":"<No Value>","WebAvailableOnWeb__c":"False","WebBenefits__c":""}