Hi Melissa ,
I tried to use POST for updating the uploadUri in an already existing prompt resourse, but its giving an error that the "prompt Id already exist" however it allows me to create a new prompt resource but is now letting me update the existing prompt resource
Are we required to use PUT for updating the prompt resource ?
My Current code to POST a prompt is below its working fine to create a new resource but is not able to modify the already existing
const platformClient = require('purecloud-platform-client-v2');
const fs = require('fs');
const request = require('request-promise');
// Get client credentials from environment variables
const PURECLOUD_CLIENT_ID = '4';
const PURECLOUD_CLIENT_SECRET ='-';
//console.log(process.env.PURECLOUD_CLIENT_ID,process.env.PURECLOUD_CLIENT_SECRET)
// Set purecloud objects
const client = platformClient.ApiClient.instance;
const architectApi = new platformClient.ArchitectApi();
// Set PureCloud settings
client.setEnvironment('mypurecloud.com');
console.log(PURECLOUD_CLIENT_ID,PURECLOUD_CLIENT_SECRET);
// Authenticate with PureCloud
let body = {
name:'test15',
description:'testing purpose only'
}
client.loginClientCredentialsGrant(PURECLOUD_CLIENT_ID, PURECLOUD_CLIENT_SECRET)
.then(() => {
console.log('Authenticated with PureCloud');
// Create new prompt
console.log('Creating new prompt...');
return architectApi.postArchitectPrompts(body)
})
.then((data) => {
// console.log(postArchitectPrompts success! data: ${JSON.stringify(data, null, 2)}
);
var Id = data.id;
return Id;
})
.then((Id) => {
console.log('Data id' + Id);
console.log("This is the" + Id);
let body1 = { language: 'en-us'}
// Create prompt resource for english
console.log('Creating prompt resource...');
return architectApi.postArchitectPromptResources(Id, body1
);
})
.then((promptResource) => {
console.log(promptResource);
// Upload WAV file to prompt
console.log('Uploading prompt...');
return request({
method: 'POST',
uri: promptResource.uploadUri,
formData: {
file: fs.createReadStream('C:\\code\\file\\new.wav')
},
headers: {
Authorization: 'bearer ' + client.authData.accessToken
}
});
})
.catch((err) => console.log(err));