API request javascript

I am trying to make an API request through Javascript via Google Sheets.
var data = {
'requestJobDescription':
{"type": "create",
"credentials":{
"partnerUserID":"ID",
"partnerUserSecret":"SECRET"
},
"inputSettings":{
"type": "policy",
"policyName": "My New Policy"
}
}
};
payload = JSON.stringify(data);
var options = {'method' : 'post',
'contentType': 'application/json',
// Convert the JavaScript object to a JSON string.
'payload' : payload};
When I try to execute this I get the following error:
{"responseMessage":"'requestJobDescription' is missing","responseCode":500}
Please could you assist?
Many thanks
Answers
Hey @mv91 !
Can you please share how you made the request? I'm not seeing anything in that code block that shows how you sent `payload` or `options` to our servers. I think knowing that will help me guide you better! Remember to redact any partner secrets/IDs if you are coping and pasting directly from your API call.
I look forward to your reply!
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up Awesome@mv91 ,
I am having the same issue. I first tried with a console application, then with SoapUI. I tried with a policy get, then with a report export. I receive the same exact response. Did you find a solution?
null
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomeHi there, I did manage to solve it.
The JSON stringify method was causing the error. If i change the 'payload' argument from my variable 'payload' to the variable 'data', then the above works.
Hopefully that makes sense and works for you - give me a shout if not and i'll try to explain/help a bit better.
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up Awesome@mv91,
Thanks for the response. I tried using your JSON in SoapUI and I'm still seeing the same error (and used my creds). Did you need to modify your JSON at all?
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomeAdditionally, I tried posting through another rest client, Insomnia, same error.
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomeOh, right. I'm unfamiliar with SoapUI but could you post your code here and I can try and have a play with it?
- Spam
- Abuse
- Report
1 · Accept Answer Off Topic Insightful Vote Up 1AwesomeThe following code snippet works:
var data = {
"type":"create",
"credentials":{
"partnerUserID":credentials.partnerUserID,
"partnerUserSecret":credentials.partnerUserSecret
},
"inputSettings":{
"type":"expenses",
"employeeEmail":credentials.employeeEmail,
"transactionList": transactions
}
}
var jobDescription = { "requestJobDescription": JSON.stringify(data) }
var url = "https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations";
var options = {
"method": "post",
"payload": jobDescription
};
response = UrlFetchApp.fetch(url, options);
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up Awesome