Get "That model does not exist" from api call in node.js
const chatGptUrl = "https://api.openai.com/v1/engines/chat-gpt/jobs";
...
const response = await axios.post(
chatGptUrl,
{
prompt,
max_tokens: 100,
n: 1,
stop: "",
},
{
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${chatGptApiKey}`,
},
}
);
const responseText = response.data.choices[0].text;
You have to set the model parameter to text-davinci-003, text-curie-001, text-babbage-001 or text-ada-001. It's a required parameter.
Also, all Engines endpoints are deprecated.
Related
I am having trouble setting up Partner Referrals when calling the PayPal API using Node.
Every time I attempt to call the API I receive the following error:
error: "invalid_token"
error_description: "The token passed in was not found in the system"
According to the documentation the URL to call is https://api-m.sandbox.paypal.com/v2/customer/partner-referrals
Looking at the URL and the error message, I believe I am getting this error because I am using production credentials, not sandbox. However, I cannot find any documentation showing the production URL for this.
Am I correct in believing this is the sandbox URL? What is the production URL if so?
Ive followed the onboarding checklist but cant seem to make this work.
Here is my code:
getAuthToken = async () => {
const clientIdAndSecret = "mylongsecret";
const authUrl = "https://api-m.paypal.com/v1/oauth2/token";
const base64 = Buffer.from(clientIdAndSecret).toString('base64')
const response = await fetch(authUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Accept-Language': 'en_US',
'Authorization': `Basic ${base64}`,
},
body: 'grant_type=client_credentials'
});
const data = await response.json();
return data;
}
setUpMerchant = async () => {
let authData = await this.getAuthToken();
const partnerUrl = "https://api-m.sandbox.paypal.com/v2/customer/partner-referrals";
let data = {
"operations": [
{
"operation": "API_INTEGRATION",
"api_integration_preference": {
"rest_api_integration": {
"integration_method": "PAYPAL",
"integration_type": "THIRD_PARTY",
"third_party_details": {
"features": [
"PAYMENT",
"REFUND"
]
}
}
}
}
],
"products": [
"EXPRESS_CHECKOUT"
],
"legal_consents": [
{
"type": "SHARE_DATA_CONSENT",
"granted": true
}
]
};
const request = await fetch(partnerUrl, {
method: 'POST',
headers: {
'Authorization': 'Bearer '+authData.access_token,
'Content-Type': 'application/json',
'data': data,
},
});
const partnerData = await request.json();
return partnerData;
}
Edit: I discovered the issue was I was running a GET request instead of a POST. The accepted answer is the correct URL
According to the documentation the URL to call is https://api-m.sandbox.paypal.com/v2/customer/partner-referrals
The production URL does not have sandbox. in the domain.
I am attempting to add dynamic links to push notifications so users tap them and open to a specific app page. I have been following the documentation and the links do not open to the page they should when I tap the push notifications but when tested in the browser the links do open to the correct page. From what I have read, there are 2 possible solutions depending on the version of firebase the project is using. The older "way" is to add a click_action property to the apns payload object, the newer way is to create a webpush object with the fcm_options property set to the value of the link. Neither of these options seems to work regardless of where the objects are placed in the request. Is my request formatted incorrectly or am I possibly missing something? Below is the current request:
const [title, body, deepLink] = titleAndBody;
let accessToken = await getAccessToken();
accessToken = "Bearer " + accessToken;
const options = {
method: "POST",
url: URL,
headers: {
Authorization: accessToken,
"Content-Type": "application/json",
},
body: JSON.stringify({
message: {
token: fcmToken,
notification: {
body: body,
title: title,
},
webpush: {
fcm_options: {
link: deepLink,
}
},
apns: {
headers: {
priority: "10",
},
payload: {
//click_action: deepLink,
aps: {
badge: 0,
mutable_content: 1,
},
},
}
},
}),
};```
I am trying to send the file with the http-request node but it is not working.
Please find the following image of Node-red flow.
In the Request Body node I have added the following code.
const inputFile = msg.payload;
const dataJson =
{
'name': 'testName',
'description':'testdescription',
'inputfile': inputFile
};
msg.payload = dataJson;
msg.url = 'myAPIurl';
msg.headers = {
'authorization': 'Bearer TOKEN Here',
'cookie': 'Cookie here',
'content-type': 'multipart/form-data;'
};
return msg;
This is giving bad request error.
In the Read File node I tried choosing both options A single UTF8-String and a single Buffer Object still I got the same error
But I tried to call the API inside function node using the request module. It is giving the proper response.
const request = global.get("request");
const fs = global.get("fs");
const url = 'API';
const tkn = 'TOken Here';
const cookie = 'cookie here';
const fl = fs.createReadStream('/tmp/node-red/app/data/filename.txt');
var options = {
method: 'POST',
url: url,
headers: {
'Authorization': tkn,
'Cookie': cookie,
},
formData: {
"name": "test121",
"description": "",
inputfile: fl
}
};
request(options, function (err, resp, body) {
console.log(body);
});
return msg;
I am not sure where I am making the mistake if I use http-request node.
From the sidebar docs for the http-request node:
File Upload
To perform a file upload, msg.headers["content-type"] should be set
to multipart/form-data and the msg.payload passed to the node must
be an object with the following structure:
{
"KEY": {
"value": FILE_CONTENTS,
"options": {
"filename": "FILENAME"
}
}
}
The values of KEY, FILE_CONTENTS and FILENAME should be set to the
appropriate values.
Following this doc, your msg.payload is wrong, it should look something like:
msg.payload: {
"name": "testName",
"description": "description",
"inputfile": {
"value": inputfile,
"options": {
"filename": "filename.txt"
}
}
}
I've been having trouble sending GraphQL queries to my GraphQLJS backend, I copy and pasted the query that I use in GraphiQL (that works fine) but it's causing a syntax error: {"errors":[{"message":"Syntax Error: Expected :, found String \": \"","locations":[{"line":2,"column":45}]}]}
graphQLTest = async () => {
var data = {
query: `mutation {
createAuctionOffering(features:"{\"year\": \"2002\", \"model\":{\"make\":\"honda\", \"selectedModel\":\"civic\"}}", start_time:"2019-03-15 19:05:45.109+00", duration:"2019-03-15 19:05:45.109+00"){
auc_id
}
}`,
}
// data = await JSON.stringify(data)
var token = jwt.sign({name:data}, 'LIdXNnmK2qJNyTGs456bR0iebf9eGZV7', {expiresIn: '10s'});
let response = await fetch('http://localhost:8000/graphql', {
method: 'post',
headers: {
"User": "charlesdsmith25#gmail.com",
"Content-Type": "application/json"
},
body: JSON.stringify({name:token})
})
let jsonResponse = await response.text()
console.log(jsonResponse)
}
I've also been using JWT but that isn't an issue seeing as the query makes it through to the backend and raises the syntax error. This is the query I'm trying to send:
var data = {
query: `mutation {
createAuctionOffering(features:"{\"year\": \"2002\", \"model\":{\"make\":\"honda\", \"selectedModel\":\"civic\"}}", start_time:"2019-03-15 19:05:45.109+00", duration:"2019-03-15 19:05:45.109+00"){
auc_id
}
}`,
}
It seems like the problems lies with the quotes
I'm trying to create media item using Google Photos API. Endpoint is documented here. If I copy and paste my payload to an API explorer which can be found in documentation, I get success:
Request inputed to an API Explorer and Successful response.
If I do the same in my node js program, I'm getting an error.
This is what I do:
const accessToken = "MyAccessToken";
payload = {
"newMediaItems": [
{
"description": "picture",
"simpleMediaItem": {
"uploadToken": "CAIS+QIASsyg4OQLX2Ao5hy6I734/b01mjk3Mqpom6DQ24iv7ZfAYLiXAy0WpOXCWJBNHrmBs6FE+a9Axu5CML+Ryu4VGawyf4skxM763mzC5GcjMY4rS/r6IwOekBIoE/aMJLJpRr1gW8jdhVJM89+kioTx9d+shyYeQDbVI8ezb1lXGp6irc9hZl7QA6xd+msXzbLD5nb+wc5CA6du95tP3buh5R5N/Knn+NwByebdEPCusl+X3p7DZ6ha72kLthUqdvwFsp8dpnGbNQBq8AFPVNHXB4C543iq+dYiRFYtICCxO8xi2cpONVT54Jl6l9rGh3Vnidwj5IwkbsXkyiN96HfRb9XLh0rCBw4ydV6Y9+C+OmTAqlQwIKy50I/ykHyzggroeJSbgphiQwFR2EbHwAeSKdsdIB03ItnunHtf3F2LRIitDRGI1n4VUEYE1dYjrrjR791ao24Dp8J3Hg8IRb8E3vFTeYMWyOk4mh/zQGInfNBnRY2ruHH0JA"
}
}
]
};
const response = await fetch('https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate', {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${accessToken}`
},
payload: JSON.stringify(payload)
});
const json = await response.json();
console.log(json);
And getting this response:
{ error:
{ code: 400,
message: 'Request must have at least one newMediaItem.',
status: 'INVALID_ARGUMENT' } }
What could go wrong here?
Any help is appreciated, thank you.
It looks like you are setting the JSON payload in the wrong parameter in your call to fetch. It should be set in the parameter body (and not in payload). The JSON itself looks okay.
This snippet should work:
const response = await fetch('https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate', {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${accessToken}`
},
body: JSON.stringify(payload)
});
Source: node-fetch 'Post with JSON' example