Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem with my script when I request a post it's always returned "Invalid Arguments". I don't know if my json parameters causing the problem. Please help me.

function getWallet() {
var header = {
    "contentType": "application/json",
    "headers":{ "Authorization": "xxxxxxxxx",
    }
};

var dataRequestPost = {

"amount": 5.95,
"email": {
"recipient_email": "customer@acme.com",
"subject": "Rebate has arrived",
"message": "Thank you for using our service."
},
"ref": {
"order_id": "string",
"email": "string",
"id1": "string",
"id2": "string",
"phone_number": "string"
},
"add_to_blacklist": false
};
var rUrl = encodeURI('https://data.seller.tools/api/v1/wallet/paypal/USD');
var executeRequest = {
'url': rUrl,
'method' : 'post',
'payload' : dataRequestPost
};
var response = UrlFetchApp.fetch(executeRequest,header);
var object = JSON.parse(response.getContentText());
Logger.log(object);
}
question from:https://stackoverflow.com/questions/66066565/invalid-argument-in-urlfetchapp-fetch

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
379 views
Welcome To Ask or Share your Answers For Others

1 Answer

You're including all of the right data, just not in the way expected as per the documentation. It should be UrlFetchApp.fetch(url, params), where params includes all other data like the method, header, and payload.

function getWallet() {
  var dataRequestPost = {
    "amount": 5.95,
    "email": {
      "recipient_email": "customer@acme.com",
      "subject": "Rebate has arrived",
      "message": "Thank you for using our service."
    },
    "ref": {
      "order_id": "string",
      "email": "string",
      "id1": "string",
      "id2": "string",
      "phone_number": "string"
    },
    "add_to_blacklist": false
  };
  var rUrl = encodeURI('https://data.seller.tools/api/v1/wallet/paypal/USD');
  var response = UrlFetchApp.fetch(rUrl, {
    "method": "post",
    "contentType": "application/json",
    "headers": {
      "Authorization": "xxxxxxxxx",
    },
    "payload": JSON.stringify(dataRequestPost)
  });
  var object = JSON.parse(response.getContentText());
  Logger.log(object);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...