Mapbox API - update tileset - api

I am trying to replace tileset resources - using the https://docs.mapbox.com/api/maps/mapbox-tiling-service/#replace-a-tileset-source. I get the 200 response code for tilesetId I provide, but I cannot see my changes when I check it in my mapbox -> studio -> tilesets section.
const updateURL = `https://api.mapbox.com/tilesets/v1/sources/${username}/${id}?access_token=${accessToken}`;
const updateTilesetOptions = {
'method': 'PUT',
'url': updateURL,
'headers': {
'Content-Type': 'multipart/form-data'
},
formData: {
'file': {
'value': Buffer.from(fileToUpload.data).toString(),
'options': {
'filename': fileToUpload.name,
'contentType': null
}
}
}
};
const updateResponse = await requestPromise(updateTilesetOptions);
console.log("updateResponse.statusCode " , updateResponse.statusCode)
if (updateResponse.statusCode >= 400) {
return {
message: updateResponse.statusMessage,
code: updateResponse.statusCode,
source: "Update Tileset"
}
}
Can someone suggest what I am doing wrong. Note: I also tried to publish tileset after udpating the source, but I am getting 400 error.

I received a reply from Mapbox. This is the correct process;
(1) Delete the existing tileset source. If you just update the existing tileset, you are indeed appending data to it.
(2) Create a new tileset source with the same ID
(3) Publish your updated tileset. Please note that this suggests that you already have a tileset recipe configured for the existing tileset
Please let me know if it works for you. It works for me now. I was missing the publishing step.

Related

Change custromer-request-type in Jira ServiceDesk via REST API

I can receive the values of an created ticket using the SD API like:
GET /servicedeskapi/request/SD-4532
and within that i find something like:
{
"issueId": "71928",
"issueKey": "SD-4532",
"requestTypeId": "121",
"serviceDeskId": "5",
...
}
whereas "requestTypeId" related to the type created by the user (e.g. has a label "Common question").
Now i want to change the request type to, let's say "Hardware issue" which have the requestTypeId of "89".
When i try to change by POST /servicedeskapi/request/SD-4532
and giving a payload of
{
"requestTypeId": "89",
}
I get a "405 - Method not allowed". Also the Jira ServiceDesk REST-API doc does not state anything about a POST method for this.
So i tried the common Jira REST-API
PUT /api/2/issue/SD-4532
and give payload
{
"fields": {
"customfield_10001": {
"requestType": {
"id": "89"
}
}
}
}
but that give me an "Field 'customfield_10001' cannot be set. It is not on the appropriate screen, or unknown." error.
The reason why the Jira ServiceDesk REST API docs do not state anything about a POST method for this because.... there is no POST method for this. You cannot change a request (issue) type simply by altering the value of the field that contains the ID (metadata) of that request type.
Do a Google search on "jira rest api change issue type" to see the many other times this question has been discussed in the past in many places. In a nutshell, changing types is not possible via the REST API, only the web UI.
Use Jira Rest API to update Jira issue information. https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-put
// This code sample uses the 'node-fetch' library:
// https://www.npmjs.com/package/node-fetch
const fetch = require('node-fetch');
const bodyData = `{
"fields": {
"customfield_10010": "ABC-09",
"customfield_10000": {
"air": "",
"type": "doc",
"name": "Sample Process",
"avatarUrl": null
}
}
}`;
fetch('https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}', {
method: 'PUT',
headers: {
'Authorization': `Basic ${Buffer.from(
'email#example.com:<api_token>'
).toString('base64')}`,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: bodyData
})
.then(response => {
console.log(
`Response: ${response.status} ${response.statusText}`
);
return response.text();
})
.then(text => console.log(text))
.catch(err => console.error(err));
email#example.com --> Your Jira emailid
<api_token> --> This is from your account token generated
Note:- Before using any API check if it's not experimental as this may cause issues in future due to sudden change in req/resp from Jira.
Try to inspect Jira dashboard network tab to understand more.

Upload a file to an IPFS node from Google Apps Script

I'm trying to upload a file to an IPFS node using Google Apps Script (GAS) without success.
However, I was able to upload a file successfully using Postman. Unfortunately Postman only gives back the source code snippet closest to GAS as a JavaScript - Fetch code, which is not working as is in GAS.
In GAS, the authentication part is working and I know that because if I'm changing the bearer token, then I'm getting invalid credentials error instead of "Invalid request format".
Test code attached where I'm getting the "Invalid request format" error from the server.
For testing purpose, the file which needs to be uploaded, could be created on the fly with the script, but has to be one from Google Drive eventually.
function test() {
let myHeaders = {'Authorization': 'Bearer ...'};
let fileBlob = Utilities.newBlob('Hello!', 'text/plain', 'TestFile.txt');
let formdata = {'file': fileBlob,
'pinataMetadata': {'name': 'TestFileNewName.txt','keyvalues': {'MetaData1': 'Test1', 'MetaData2': 'Test2'}},
'pinataOptions': {'cidVersion': 0}};
let requestOptions = {
method: 'post',
headers: myHeaders,
papyload: formdata,
muteHttpExceptions: true
};
let url = "https://api.pinata.cloud/pinning/pinFileToIPFS";
let response = UrlFetchApp.fetch(url, requestOptions);
let responeText = JSON.parse(response.getContentText());
Logger.log(responeText);
}
If your access token of Bearer ... is the valid value for using the API, how about the following modification? From the official document, I thought that in the case of your formdata, the values of pinataMetadata and pinataOptions might be required to be the string type.
From:
let formdata = {'file': fileBlob,
'pinataMetadata': {'name': 'TestFileNewName.txt','keyvalues': {'MetaData1': 'Test1', 'MetaData2': 'Test2'}},
'pinataOptions': {'cidVersion': 0}};
To:
let formdata = {
'file': fileBlob,
'pinataMetadata': JSON.stringify({ 'name': 'TestFileNewName.txt', 'keyvalues': { 'MetaData1': 'Test1', 'MetaData2': 'Test2' } }),
'pinataOptions': JSON.stringify({ 'cidVersion': 0 })
};
And also, please modify papyload: formdata, to payload: formdata,. This has already been mentioned by
TheMaster's comment.
References:
Pin File
fetch(url, params)

How to configure dynamic links for a Firebase project?

Since google is shutting down it's url shortening service, I want to move my project to FDL.
I am using the api to shorten the url following this:
https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_a_long_link
and I am using Postman to call the api but I keep getting this error.
{
"error": {
"code": 400,
"message": "Your project has not configured Dynamic Links. [https://firebase.google.com/docs/dynamic-links/rest#before_you_begin]",
"status": "INVALID_ARGUMENT"
}
}
I am using the correct api key and the project id.
Had the same issue- and thats the answer i got from the firebase team:
Take note that to be able to view your Dynamic Link domain you'll have
to add an app first. If you're using Firebase Dynamic Link as a
substitute to Google Shortener, you can create a sample application
(dummy app) for your project to proceed creating a Firebase Dynamic
Links. Just enter dummy values for the iOS bundle ID or Android
package name (ex: “my.dummy.app”) to continue.
then you'll put the id you'll get from it (e.g. https://dedfgu.app.goo.gl) instead of the place holder (https://abc123.app.goo.gl).
Good luck!
You can try following way
var Url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key={API-Key}";
$.ajax({
type: 'POST',
dataType: 'json',
url: Url,
contentType:'application/json',
data: JSON.stringify({
"dynamicLinkInfo": {
"domainUriPrefix": "https://newxpress.page.link",
"link": {Your-Link},
"androidInfo": {
"androidPackageName": "com.newxpress"
},
"iosInfo": {
"iosBundleId": "com.newxpress.iosapp"
}
}
}),
success: function (jsondata) {
console.log(jsondata);
},
error: function (result) {
console.log(result);
}
});

attach a pdf to an email in meteor

This Meteor server code tries to attach a pdf file but giving errors on server startup. I want avoid saving the file locally first.
it is using pascoual:pdfkit.
The error I am getting is:
Error: Message failed: 421 Timeout waiting for data from client.
Meteor doc point to mailcomposer documentation, but the issue is how to integrate the pdf doc in the attachments. Any ideas? Thanks
Meteor.startup(() => {
Invoice.email();
};
// invoice.js
use strict";
let PDFDocument = require ('pdfkit');
let metaData = {
'Title': 'Invoice',
'Author': 'myName',
};
export const Invoice = {
'make': function () {
let doc = new PDFDocument(metaData);
doc.text('my company').text('company number');
return doc;
},
'email': function () {
let inv = Invoice.make();
Email.send({
to: 'myemail#comp.com',
from: 'personal#company.com',
subject: 'Invoice',
text: ' Please see the attached invoice',
attachments: {
filename: 'invoice.pdf',
content: inv // <=== this is the issue
});
}
};
As per Documentation, the content definition is
content - String, Buffer or a Stream contents for the attachment
Link to mailcomposer documentation.
If I am not wrong the Invoice.make() is not returning expecting format of blob. Kindly check the Stream and type so that you know you get what you are creating.
Link to more Supporting details

fail to create operation with c8yDeviceControl.creat

I'm new to cumulocity application development. Now I'm learning to use Smart App Toolkit to develop HTML5 application.
I could create device in my Tenant, and could run some operations with servces provided in the SDK. However, I failed to create operation with c8yDeviceControl.create(). I got 400 (bad request) error code after the operation, and if I look deeper with chrome develop tool, it shows
{error: "Failed to parse JSON string"},
Here is my code, which I pick up from the Smart SDK sample code, with modifition to reference my deviceId:
var operation = {
deviceId: 12111,
com_cumulocity_model_WebCamDevice: {
name: 'take picture',
parameters: {
duration: '5s',
quality: 'HD'
}
}
};
c8yDeviceControl.create(operation);
Could anyone provide me a help to fix this problem?
Thanks.
The deviceID needs to be a string. This works:
var operation = {
deviceId: '1211',
com_cumulocity_model_WebCamDevice: {
name: 'take picture',
parameters: {
duration: '5s',
quality: 'HD'
}
}
};
c8yDeviceControl.create(operation);
Sorry for the inconvenience, we'll update the documentation.