Always getting error "requestId is required" when doing POST on quickbooks payment API Apps Script - rest

Im creating a script that will process a credit transaction and I always getting this response:
{
"errors": [
{
"code": "PMT-4002",
"type": "invalid_request",
"message": "requestId is required.",
"detail": "requestId",
"infoLink": "https://developer.intuit.com/v2/docs?redirectID=PayErrors"
}
]
}
Im trying to figure out where to put the "request-id" parameter on the request body. Here is my code:
function QBOcreatecharge(){
var token = "TOKEN"
var service = getQuickbooksService();
if (service.hasAccess()) {
var url = 'https://sandbox.api.intuit.com/quickbooks/v4/payments/charges'
var Details =
{
"amount": "80.00",
"currency": "USD",
"capture": "false",
"token": token
}
var params = {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
},
contentType: 'application/json',
method: 'POST',
payload: JSON.stringify(Details),
muteHttpExceptions:true
}
var response = UrlFetchApp.fetch(url, params);
var value = JSON.parse(response.getContentText())
Logger.log(value)
}
else{
var authorizationUrl = service.getAuthorizationUrl();
Logger.log('Open the following URL and re-run the script: %s', authorizationUrl);
}
}
How do I add the requestId parameter? I tried to insert it on the link, on the header and nothing work. Im using UrlFetch on Google Apps Script. Any help will be appreciated. Thanks!

The Request-Id is a header you need to send. e.g.:
headers: {
Authorization: 'Bearer ' + service.getAccessToken(),
'Request-Id': your unique value here
},
Intuit documents it here:
https://developer.intuit.com/app/developer/qbpayments/docs/develop/explore-the-quickbooks-payments-api/rest-api-features#identifiers

Related

HandshakeException: Connection terminated during handshake

I'm developing my first Flutter mobile app, and I'm facing an error trying to fetch data from API REST.
I set 2 get request using HTTP packages:
-the first is a single request, and it's fetching 'work orders' with attributes immediately available;
-the second one is another get request that fires per every 'work order' retrieved from the first request that take others attributes.
Basically, I run the first get request and I made a for loop to fire the second get request for all data.
So, the first request is working fine, instead the second one is giving me the following error for every time it fires:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled
Exception: HandshakeException: Connection terminated during handshake
The strange things are that it works, but I can't anyway render the widget with the error.
This is the code I used for fetching data:
Future<void> fetchAndSetWorkOrders([bool filterByUser = false]) async {
var url = Uri.parse(
'https://API_URL/wo?fields=id,code,description,statusCode,actionType,assignedTo&filter[wo][statusCode]=REQUEST');
try {
var response = await http.get(
url,
headers: {
"token": authToken,
},
);
var extractedData = json.decode(response.body) as Map<String, dynamic>;
final List<WorkOrder> loadedWorkOrders = [];
if (extractedData['data'] == null) {
return;
}
extractedData['data'].forEach(
(attribute) async {
var actionType_url = Uri.parse(attribute['relationships']
['actionType']['links']['related']);
var actionType_response = await http.get(
actionType_url,
headers: {
"token": authToken,
},
);
var actionTypeData = json.decode(actionType_response.body) as dynamic;
var actionType_code =
actionTypeData['data']['attributes']['code'];
print(actionType_code);
loadedWorkOrders.add(
WorkOrder(
id: attribute['id'],
code: attribute['attributes']['code'],
description: attribute['attributes']['description'],
statusCode: attribute['attributes']['statusCode'],
actionType: actionType_code,
),
);
},
);
This is an example of a JSON file I get from the API.
{
"data": [
{
"id": "17db1506f6d-3ca8",
"type": "wo",
"links": {
"self": "https://API_URL/wo/17db1506f6d-3ca8",
"workflow-transitions": "https://API_URL/wo/17db1506f6d-3ca8/workflow-transitions"
},
"attributes": {
"description": "test",
"code": "TEST",
"statusCode": "REQUEST"
},
"relationships": {
"actionType": {
"links": {
"self": "https://API_URL/wo/17db1506f6d-3ca8/relationships/actionType",
"related": "https://API_URL/wo/17db1506f6d-3ca8/actionType"
}
},
"assignedTo": {
"links": {
"self": "https://API_URL/wo/17db1506f6d-3ca8/relationships/assignedTo",
"related": "https://API_URL/wo/17db1506f6d-3ca8/assignedTo"
}
}
}
},
]
}
I hope that someone can help me to solve this problem.

Getting POST Request Message using React.JS

I am writing a program which has a "sign up" functionality. The front-end is created using React.JS. So far, I am able to using this code to send a post request in React.JS:
fetch('http://localhost:2000/users/signup/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"email": "testing#gmail.com",
"password": "secret",
"name": "matthew",
"organization": "Apple"
})
}).then(function(response) {
return response.json();
});
This works perfectly - for the user information is now in the database. However I am not sure how to get the response JSON using response.json(). I want to be able to take the response, get the message string, and display it to my user on the front-end. This is the response when I run the same post request on Postman.
{
"message": "New user created"
}
Thanks for the help!
response.json() returns a promise, so you need one more then to get the actual data:
.then(function(response) {
return response.json();
})
.then(function(data) {
console.log(data);
})
see https://developer.mozilla.org/en-US/docs/Web/API/Body/json

Azure Machine Learning REST API: no body

I am simply strying to call the REST API end point of a machine learning experiment created with Azure. I keep getting this error message:
{
"error": {
"code": "BadArgument",
"message": "Invalid argument provided.",
"details": [
{
"code": "RequestBodyInvalid",
"message": "No request body provided or error in deserializing the request body."
}
]
}
}
I have looked it up on their documentation: https://learn.microsoft.com/en-us/azure/machine-learning/machine-learning-web-service-error-codes
All it says is that my bod is empty, I am not sure how can it be empty, here is my code:
router.post('/rating/new', function(req, res) {
var postData = {
"Inputs": {
"input2":
[
{
'Col1': "A11",
'Col2': "6",
'Col3': "A34",
'Col4': "A43",
'Col5': "1169",
'Col6': "A65",
'Col7': "A75",
'Col8': "4",
'Col9': "A93",
'Col10': "A101",
'Col11': "4",
'Col12': "A121",
'Col13': "67",
'Col14': "A143",
'Col15': "A152",
'Col16': "2",
'Col17': "A173",
'Col18': "1",
'Col19': "A192",
'Col20': "A201",
'Col21': "1",
}
],
},
"GlobalParameters": {
}
};
// Configure the request
var options = {
url: config.ML_PREDICTIVE.url,
method: 'POST',
headers: {
'Content-Type':'application/json',
'Authorization':('Bearer ' + config.ML_PREDICTIVE.apiKey)},
form: postData
}
console.log(JSON.stringify(options));
// Start the request
request.post(options, function (error, response, body) {
if(error){
res.status(403).send(error);
}
if(response.statusCode != 200){
res.status(403).send(response.body);
}
if (!error && response.statusCode == 200) {
console.log(body)
}
})
});
The only thing I see that could go wrong is that "form" in the request is not considered body by azure, I have tried with "body" as well no success.
Please help !
According to the code you provided, the variable postData is not valid JSON string. You'd need to use JSON.stringify() method to convert postData value to a JSON string before you send a POST request.

Ionic Push is no longer working 1.x

Everything has been working great then now I get the following error:
ionic.bundle.js:18463 OPTIONS https://push.ionic.io/api/v1/push net::ERR_NAME_NOT_RESOLVED
i cant seem to send a push using the following:
// Encode your key
var auth = btoa(privateKey + ':');
// Build the request object
var req = {
method: 'POST',
url: 'https://push.ionic.io/api/v1/push',
headers: {
'Content-Type': 'application/json',
'X-Ionic-Application-Id': appId,
'Authorization': 'basic ' + auth
},
data: {
"tokens": devices,
"notification": {
"alert": message,
"ios":{
"priority": 10,
"badge": 1,
"payload": {"path": path}
}
}
}
};
// Make the API call
$http(req).success(function(resp){
// Handle success
console.log("Ionic Push: Push success!");
}).error(function(error){
// Handle error
console.log("Ionic Push: Push error...");
});
everything just stopped working - it was working beautifully before.
thanks for your help
I think they have change the URL and format little bit.
New URL is https://api.ionic.io/push/notifications
Payload
{
"tokens":["device_token_1", "device_token_2"],
"profile": "prod",
"notification": {
"title" : "Title of the message",
"message": "Ur message!"
}
}

Sending push notification using ionicframework cloud api

Hello am trying to send push notification from my nodejs server to ionicframework API and am getting an error here is my code
var token = '66a5c472b52d3210b591f717b5b996312f8xxxxxxxxxxxx';
var title = 'test';
var message = 'message';
var options = {
method: 'POST',
url: 'https://api.ionic.io/push/notifications',
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
},
json : {
"send_to_all": true,
"profile" : "my-profile",
"notification": {
"title": title,
"message": message,
"android": {
"title": title,
"message": message
},
"ios": {
"title": title,
"message": message
}
}
}
};
request(options, function(err, response, body) {
if (err) throw new Error(err);
console.log(body);
});
am getting this error
{ error:
{ message: 'JWT decode error occurred.',
link: null,
type: 'Unauthorized' },
meta:
{ status: 401,
version: '2.0.0-beta.0',
request_id: '75726406-3060-4329-a59e-3bd7f9ca90c8' } }
What could I be doing wrong
I think there is issue with your authorization header.
In header you're putting token, but please make sure it is API token.
Also make a postman request first and check whether it is working fine.
add content-type and authroization parts in header only..
then check the difference..
Thanks
Basu