Hi @Jaycee_Lewis ,
I am requesting a json file URL, which is present in the file section of Hubspot portal where the public app is installed, and the file name is same as the portal ID.json . Once the json file content received we will display it on the CRM card, there is no issue for display the content on the CRM card, if we use static portal ID.json file in our code then it execute suceessfully and display the content on the CRM card without any error.
Our issue is to fetch Portal ID and with the use of that ID getting the Json file.
Here is my code please look at it and help me as soon as possibe.
----------------------------------------------------------------------------------------------------------
exports.main = (context, sendResponse) => {
const hs_object_id = context.params.hs_object_id;
const portalId = context.params.portalId;
var request = require(“request”);
var request_url_filter = ‘https://’+portalId+‘.fs1.hubspotusercontent-na1.net/hubfs/’+portalId+‘/’+portalId+‘.json’;
var options = { method: ‘GET’,
url: request_url_filter,
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
var crm_quote_data = ‘’;
if( body[‘deals_quotes’] !== undefined ) {
var deals_quotes = body[‘deals_quotes’];
var deals_quotes_len = body[‘deals_quotes’].length;
for(var i=0; i<deals_quotes_len; i++) {
var deal_id = deals_quotes[i].deal_id;
if( deal_id == hs_object_id ) {
crm_quote_data = deals_quotes[i].CRM_quote_data;
}
}
if( crm_quote_data == ‘’ ) {
var results = [];
var dataObj = {
“objectId”: 123,
“title”: "Vendori quotes not available for this Deal, please update the JSON file. ",
“created”: “2016-09-15”,
“priority”: “HIGH”,
“project”: “API”,
“reported_by”: “msmith@hubspot.com”,
“description”: “Customer reported that the APIs are just running too fast. This is causing a problem in that they’re so happy.”,
“reporter_type”: “Account Manager”,
“status”: “In Progress”,
“ticket_type”: “Bug”,
“updated”: “2016-09-28”
};
results.push(dataObj);
crm_quote_data = {
“settingsAction”: {
“type”: “IFRAME”,
“width”: 890,
“height”: 748,
“uri”: “Vendori”+hs_object_id,
“label”: “Create Quote”
}, results };
}
} else {
var results = [];
var dataObj = {
“objectId”: 123,
“title”: "404 JSON file not found, please upload the file. ",
“created”: “2016-09-15”,
“priority”: “HIGH”,
“project”: “API”,
“reported_by”: “msmith@hubspot.com”,
“description”: “Customer reported that the APIs are just running too fast. This is causing a problem in that they’re so happy.”,
“reporter_type”: “Account Manager”,
“status”: “In Progress”,
“ticket_type”: “Bug”,
“updated”: “2016-09-28”,
“properties”: [
{
“label”: "Note: ",
“dataType”: “STRING”,
“value”: “File should place on root of the file section and it’s name should be “+portalId+”.json”
}
]
};
results.push(dataObj);
crm_quote_data = {
“settingsAction”: {
“type”: “IFRAME”,
“width”: 890,
“height”: 748,
“uri”: “https://app.hubspot.com/files/“+portalId+”/”,
“label”: “Upload JSON File”
}, results };
}
sendResponse({body: crm_quote_data, statusCode: 201});
});
};
----------------------------------------------------------------------------------------------------------
Thanks