PUT - Opportunity value - not working


I am loading opportunity with following GET command:

var headers = {
'Authorization':'Basic myEncodedKey',

var options = {
"headers": headers,


function getInsightlyOpportunity(opportunityID){
var url = 'https://api.insight.ly/v2.1/opportunities/'+opportunityID;
var response = UrlFetchApp.fetch(url, options );
return response;


Loading opportunity properly. Now on object returned want to set up value and send whole JSON object back:

function setInsightlyTenderValue(opportunityID, value) {
var opportunity = JSON.parse(getInsightlyOpportunity(opportunityID));
opportunity.BID_AMOUNT = value;

var options = {
"method": "PUT",
"headers": headers,
"payload": opportunity,

var url = 'https://api.insight.ly/v2.1/opportunities';
UrlFetchApp.fetch(url, options );



but get response:

Request failed for https://api.insight.ly/v2.1/opportunities returned code 400. Truncated server response: Value cannot be null. Parameter name: key (use muteHttpExceptions option to examine full response) (line 46, file "Insightly")


This is very odd, as looks like validation mechanism require parameter key but can not see it in JSON object received.

Can you help?

Thank you.



  • Official comment

    Hi Robert. Would you mind posting the entire JSON payload that is being sent to the server? It is a bit difficult to see what is going on with what is posted here. What I can tell you is that we don't require anything called "key" for Opportunities, so that error message is misleading. Something is probably null that shouldn't be, but it's not "key". 

    It could be that something is not being parsed correctly, or something is getting nulled out inadvertently by the code. Are you using the Python SDK? It could be that there is a bug in the Python SDK. I would encourage you to use Postman to test the request that you are making. Once it is working there then it will be easier to look into why the method you're using in code is not matching the request that you have working in Postman.

    I hope that helps; please post back if you have further questions or if you're able to figure out the problem.

    Nate Cook

    Comment actions Permalink
  • Hello Nate. 

    Thank to prompt reply.

    Actually already solve the problem.

    Added to my options:

    "contentType" : "text/json",


    and then JSON.stringify(opportunity)

    Problem solved.

    Thank you.

    Comment actions Permalink
  • Great! Thank you for posting the solution you found!


    Comment actions Permalink

Please sign in to leave a comment.