Apps Script projects.deployments.create throwing GaxiosError: Requested entity was not found - google-apps-script

I am trying to set up a onEdit trigger for Google SHeets using the Apps Script API.
I have managed to create and update a script project by the code given below (this is working fine)
const createScriptRes = await this.script.projects.create({
requestBody: {
title,
},
})
if (createScriptRes.err) {
responseObj.err = createScriptRes.err
return responseObj
}
const scriptId = createScriptRes.data.scriptId
const updateScriptRes = await this.script.projects.updateContent({
scriptId,
auth: this.auth,
resource: {
files: [
{
name: 'gsheet_trigger',
type: 'SERVER_JS',
source: `
function onEdit(e) {
UrlFetchApp.fetch("http://localhost:3000/webhooks/gsheet", {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify({ rowInd: e.range.getRowIndex() })
})
}
function setup() {
const sheet = SpreadsheetApp.openById("SHEET_ID")
ScriptApp.newTrigger("onEdit").forSpreadsheet(sheet).onEdit().create()
}
`,
},
{
name: 'appsscript',
type: 'JSON',
source: `{"timeZone":"America/New_York","exceptionLogging": "CLOUD", "executionApi": {
"access": "ANYONE"
}}`,
},
],
},
})
Now, I am facing "Requested entity not found" when I try to deploy this script project using the below code.
const deployScriptRes = await this.script.projects.deployments.create({
scriptId,
requestBody: {
versionNumber: 1,
manifestFileName: 'appsscript',
},
})
The full error body is
errors: [
{
message: 'Requested entity was not found.',
domain: 'global',
reason: 'notFound'
}
]
I have looked for the solution on documentation, github issues and StackOverflow, but didn't find anything specific to this

Try changing requestBody to resource and remove extra comma:
const deployScriptRes = await this.script.projects.deployments.create({
scriptId,
resource: {
versionNumber: 1,
manifestFileName: 'appsscript' //remove comma at end
},
})

Related

SyntaxError: Unexpected token \n in JSON at position

I have a roblem while directing a request from Cloud Flare workers to my API. When I catch the error I get this:
SyntaxError: Unexpected token \n in JSON at position 240
when I did some research I saw some articles about it being about JSON.parse. But I couldn't find the solution.
Example Request Body:
{"link": "link", "provider": "company", "oauth": "key", "testText": "text"}
Cloud Flare Workers Code:
addEventListener('fetch', function (event) {
const { request } = event;
const response = handleRequest(request).catch(handleError)
event.respondWith(response)
})
async function handleRequest(request) {
const realBody = JSON.parse(`${await request.json()}`
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
.replace(/\f/g, "\\f"));
const stringifiedJSON = JSON.stringify(realBody);
const init = {
body: stringifiedJSON,
method: "POST",
headers: {
"content-type": "application/json;charset=UTF-8",
},
};
const initLog = {
body: JSON.stringify({ msg: { discountBodyStringified: realBody }}),
method: "POST",
headers: {
"content-type": "application/json;charset=UTF-8",
},
}
const responseLogger = await fetch("https://example.com/log", initLog)
console.log(responseLogger)
console.log(init)
const response = await fetch("https://example.com", init)
return new Response("tweet sent!")
}
function handleError(error) {
console.error('Uncaught error:', error)
const { stack } = error
const initLog = {
body: JSON.stringify({ msg: { error: stack || error }}),
method: "POST",
headers: {
"content-type": "application/json;charset=UTF-8",
},
}
const responseLogger = fetch("https://example.com/log", initLog)
return new Response(stack || error, {
status: 500,
headers: {
'Content-Type': 'text/plain;charset=UTF-8'
}
})
}
problem is not in the code, the problem in request which you are or front app is sending somewhere you lived extra comma or didnt close field.
For example:
{
"name": "Alice",
}
this will give same error as SyntaxError: Unexpected token \n in JSON at position because extra comma is there or
{
"name": "Alice
}
this also will throw error because I didnt close quotes

How do i make a POST request to an api in React Native?

I am trying to make a Post request to an api but for some reason i am getting a 400 feedback in the process. Being that i am a beginner at this, i can't really figure out where i am getting it wrong. I understand 400 error has to do with incorrect syntax but i am not sure that is the case here. I also checked out the other related posts but none helped address my problem. I have also read through the documentation over and over again but still can't see where i am making a mistake. I will appreciate if you helped me point out the problem.
myPostRequest(){
var mybody = {
"amount": "5.0",
"currency": "EUR",
"externalId": "6547864",
"payer": { "partyIdType": "MSISDN","partyId": "0977948551"}
}
mybody = JSON.stringify(mybody);
var token = "mytoken";
//POST request
fetch('https://sandbox.momodeveloper.mtn.com/collection/v1_0/requesttopay', {
method: "POST",
headers: {
'Authorization': 'Bearer '+token,
'X-Reference-Id': 'f9b8b0a-XXXXXXXXXX',
'X-Target-Environment': 'sandbox',
'Ocp-Apim-Subscription-Key': '14d2a71dXXXXXXXXX',
},
body: mybody,
})
.then((responseJson) => {
alert(JSON.stringify(responseJson));
console.log(responseJson);
})
.catch((error) => {
alert(JSON.stringify(error));
console.error(error);
});
}
Use axios/apisauce instead of fetch
apisauce example:
import { create } from 'apisauce';
const api = create({
baseURL: `http://example.com`,
});
const response = await api.post('/path/to/', body, { headers });
In your case:
import { create } from 'apisauce';
const api = create({
baseURL: `https://sandbox.momodeveloper.mtn.com`,
});
const response = await api.post(
'/collection/v1_0/requesttopay',
{
"amount": "5.0",
"currency": "EUR",
"externalId": "6547864",
"payer": { "partyIdType": "MSISDN", "partyId": "0977948551" }
},
{
headers: {
'Authorization': 'Bearer ' + token,
'X-Reference-Id': 'f9b8b0a-XXXXXXXXXX',
'X-Target-Environment': 'sandbox',
'Ocp-Apim-Subscription-Key': '14d2a71dXXXXXXXXX',
}
}
);

Failed to construct 'PaymentRequest': Iterator getter is not callable

I'm following a tutorial about new PaymentRequest API but I get an error:
Uncaught TypeError: Failed to construct 'PaymentRequest': Iterator
getter is not callable.
at startPayment ((index):45)
function startPayment(){
if (!window.PaymentRequest) {
// PaymentRequest API is not available. Forwarding to
// legacy form based experience.
location.href = '/checkout';
return;
}
const methods = {
supportedMethods: "basic-card",
data: {
supportedNetworks: [
'visa', 'mastercard', 'amex', 'discover',
'diners', 'jcb', 'unionpay'
]
},
}
const details = {
total: {
label: 'Tyle musisz zabulić',
amount: { currency: 'PLN', value : '22.15' }
},
displayItems: [{
label: 'Narkotyki',
amount: { currency: 'PLN', value: '22.15' }
}],
}
const options = {
requestShipping: true,
requestPayerEmail: true,
requestPayerPhone: true,
requestPayerName: true,
shippingType: 'delivery'
};
const request = new PaymentRequest(methods, details, options) // this line fails
request.show().then(response => {
// [process payment]
// send to a PSP etc.
response.complete('success');
});
}
What does it mean and how can I fix it?
MacOS Chrome version: 72.0.3626.121 64bit
payment methods should be an array:
const methods = [
{
supportedMethods: "basic-card",
data: {
supportedNetworks: [
'visa', 'mastercard', 'amex', 'discover',
'diners', 'jcb', 'unionpay'
]
},
}
]

Unable to translate created object using autodesk forge derivativesApi

I am trying to translate an object after uploading it but I keep getting 400 Bad Request error.
I am using the forge-api-nodejs-client
here is how my code looks like
var base64 = require('js-base64').Base64;
objectsApi.uploadObject(
bucket.bucketKey,
file.originalname,
file.size,
file.buffer,
{},
oAuth2TwoLegged,
credentials
)
.then(
response => {
const objectDetails = response.body;
// objectId => urn:adsk.objects:os.object:d62db090-0c47-11e8-9a36-7bd06cedf058/Pawn.stl
const job = {
input: {
urn: base64.encode(objectDetails.objectId)
},
output: {
formats: [
{
type: "obj"
}
]
}
};
derivativesApi
.translate(job, {}, oAuth2TwoLegged, credentials)
.then(
data => {
res.send(data);
},
err => {
// it fails here with 400 status error
res.send(err);
}
);
},
err => {
res.send(err);
}
);
my job object looks like this:
{
input:{
urn: 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZDYyZGIwOTAtMGM0Ny0xMWU4LTlhMzYtN2JkMDZjZWRmMDU4L1Bhd24uc3Rs'
},
output: {
formats: [
type: "obj"
]
}
}
the response
{
statusCode: 400,
statusMessage: "Bad Request"
}
I have also a tutorial using the Forge NPM to do the whole process of creating bucket to upload file and translate it. I think the part you are having problems with is the uploading part
Check this https://github.com/jaimerosales/modelderivative-nodejs-tutorial/blob/master/uploader.js#L145
Your payload is incorrect, it should look like below:
{
input: {
urn: "...place your design url here ..."
},
output:{
force: false, // true if you want to force regenerate the obj, after new model upload for ex (optional)
formats: [{
type: 'obj',
advanced: {
modelGuid: "...", // model GUID, required
objectIds: [-1] // array of dbIds to export, required. Pass [-1] to export full model, or specific dbIds ex: [49, 56, ...]
}
}],
destination: {
region: 'us' // default, optional can be ['us', 'emea']
}
}
})
You need to perform additional API call to retrieve the model GUID: see GET :urn/metadata for more details

Posting JSON format from Google script to PandaDoc API

I am trying to create a new document in PandaDoc via de Google Scipt editor.
Everything works fine (document is created with the right name and template), but the recipients don't come through. If I post the same parameters with Postman the recipients do come through. It probably has to do with the format of the recipient parameters but I am not experienced enough to see what.
Here is my code:
function createPandaDoc() {
var formData = {
"name": "Sample Document5",
"template_uuid": "BDZRbdUt7abCbYFBBBREaL",
"recipients": [
{
"email": "john#appleseed.com",
"first_name": "John",
"last_name": "Appleseed",
"role": "Signer"
}
]
};
// Because payload is a JavaScript object, it will be interpreted as
// as form data. (No need to specify contentType; it will automatically
// default to either 'application/x-www-form-urlencoded'
// or 'multipart/form-data')
var options = {
'method' : 'post',
'headers' : {
Authorization : 'Bearer xxx',
contentType : 'application/json'
},
'payload' : formData
};
UrlFetchApp.fetch('https://api.pandadoc.com/public/v1/documents', options);
}
If you have any idea, please let me know!
Thanks Chris
Got it! Should have been:
function createPandaDoc() {
var formData = {
'name': 'Sample Document5',
'template_uuid': 'BDZRbdUt7abCbYFBBBREaL',
'recipients': [
{
'email': 'john#appleseed.com',
'first_name': 'John',
'last_name': 'Appleseed',
'role': 'Signer'
}
]
};
// Because payload is a JavaScript object, it will be interpreted as
// as form data. (No need to specify contentType; it will automatically
// default to either 'application/x-www-form-urlencoded'
// or 'multipart/form-data')
var options = {
'method' : 'post',
'contentType' : 'application/json',
'headers' : {
Authorization : 'Bearer xxxx'
},
'payload' : JSON.stringify(formData)
}
UrlFetchApp.fetch('https://api.pandadoc.com/public/v1/documents', options);
}