function Run_Mutation(){
var token = "Bearer [Censored]"
var Business_ID = "[Censored]"
var url = "https://gql.waveapps.com/graphql/public";
var query =
"mutation Mutation($input: CustomerCreateInput!) {\
customerCreate(input: $input) {\
didSucceed\
}\
}";
var variables = {
"input": {
"businessId": Business_ID,
"name": "Santa",
"firstName": "Saint",
"lastName": "Nicholas",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94e7f5fae0f5d4f1ecf5f9e4f8f1baf7fbf9">[email protected]</a>",
"address": {
"city": "North Pole",
"postalCode": "H0H 0H0",
"provinceCode": "CA-NU",
"countryCode": "CA"
},
"currency": "CAD"
}
};
var headers = {
'muteHttpExceptions' : true,
'contentType' : 'application/json',
'authorization' : token
}
var data = {
"operationName": "Mutation",
"query" : query,
"variables" : variables
}
var options = {
'method' : 'POST',
'headers' : headers,
'payload' : data
}
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
}
This code snippet demonstrates a mutation request using GraphQL. It pertains to creating a customer in Wave Accounting API for a specific business while keeping sensitive information censored. The customer details are fictitious placeholders.
The script operates smoothly on platforms like the Wave API Playground and Apollo. Yet, when implemented on Google App Script, an error arises:
POST body missing. Did you forget use body-parser middleware?
To resolve this issue, the integration of body-parser middleware into the script may be necessary. It is speculated that the absence of such middleware impedes the interaction with the Wave API server specifically on G.A.S. Alternatively, modifications can be made to ensure successful mutation requests within G.A.S.
Note that query requests function without any problems, with mutations being the primary concern.