"The x-ms-tags header is formatted incorrectly" when Assigning Multiple Blob Tags via "Put Blob" HTTP request - http-headers

I have created an HTTP Put request to Azure Blob Storage which I have successfully run and managed to add a single Blob index tag using the following headers for "x-ms-tags"...
{
"Content-length": "0",
"content-type": "application/pdf",
"x-ms-version": "2020-04-08",
"x-ms-blob-content-disposition": "attachment; filename=\"test1.pdf\"",
"Date": "7/15/2022 11:53 AM",
"x-ms-blob-type": "BlockBlob",
"x-ms-tags": "blobtag=value"
}
Blob Object Result:
However, I have a requirement to add multiple tags to a blob object via this PUT Blob request. Reading the MS documentation I should be able to achieve this by modifying the "x-ms-tags" header. This is what I tried...
{
"Content-length": "0",
"content-type": "application/pdf",
"x-ms-version": "2020-04-08",
"x-ms-blob-content-disposition": "attachment; filename=\"test1.pdf\"",
"Date": "7/15/2022 11:50 AM",
"x-ms-blob-type": "BlockBlob",
"x-ms-tags": "\"Project\"='Contoso'\"test1\"='1'"
}
Unfortunately, this method returns an error for the "x-ms-tags" header value.
TagsHeaderInvalidFormatThe x-ms-tags
header is formatted incorrectly.
Any advice on this challenge would be appreciated. Thank you for your time.

The documentation is incorrect. You would need to include & as tag separator.
Please try the following:
"x-ms-tags": "Project=Contoso&test1=1"
This is how JavaScript SDK for Azure Storage is doing it:
export function toBlobTagsString(tags?: Tags): string | undefined {
if (tags === undefined) {
return undefined;
}
const tagPairs = [];
for (const key in tags) {
if (Object.prototype.hasOwnProperty.call(tags, key)) {
const value = tags[key];
tagPairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
}
}
return tagPairs.join("&");
}

Related

how to specify certain field which is inside array in restapi

I have an api link https://apilink.com?_fields=id,name,images which gives me the following format
[
{
"id": 229210,
"name": "Basic Electrical Knowledge",
"images": [
{
"id": 229211,
"date_created": "2023-01-13T18:34:39",
"date_created_gmt": "2023-01-13T07:34:39",
"date_modified": "2023-01-13T18:34:39",
"date_modified_gmt": "2023-01-13T07:34:39",
"src": "https://sampleSite.in/wp-content/uploads/2023/01/SomeUrlSource.jpg",
"name": "Basic Electrical Knowledge",
"alt": ""
}
]
}
]
I want to access only src from images[]. How do I retrieve this from the link. When clicking the link I want to display this:
[
{
"id": 229210,
"name": "Basic Electrical Knowledge",
"src": "https://sampleSite.in/wp-content/uploads/2023/01/SomeUrlSource.jpg"
}
]
How do I do this?
I tried to solve this by providing this parameters:
https://apilink.com?_fields=id,name,images=src
You can achieve this by making a GET request to the API link and then using a library such as JSON.parse() to parse the response and extract the necessary data. After that, you can use a for loop to iterate over the 'images' array in the response and extract the 'src' key from each object in the array. Finally, you can construct a new object with the desired format and return it.
fetch(https://apilink.com?_fields=id,name,images)
.then(response => response.json())
.then(data => {
let newData = []
data.forEach(item => {
let newItem = {
id: item.id,
name: item.name,
src: item.images[0].src
}
newData.push(newItem)
});
return newData;
})
.then(newData => {
console.log(newData);
});
Note that this code snippet is simplified and doesn't handle errors, it's only serve as an example of how you could do it.
Assuming that you can't make server-side changes, implement a little script, and want the result just manipulating the URI the response is no.
The URI is referring to a resource in the server, the _fields seem like a projection to make to the attributes of the desired resource.
In this case, you are trying to make a transformation on the resource given by the server through. If the server does not implement such functionality you must do it by yourself.
You want to transform the attribute images that has type [Object] to a String.
A code snippet like the answered by #RASIKA EKANAYAKA would fit your requirement.

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.

cannot subscribe to onedrive API

I tried to subscribe to onedrive webhooks by hitting
https://graph.microsoft.com/v1.0/subscriptions
https://graph.microsoft.com/beta/subscriptions
parameters are:
"changeType": "created,updated,deleted",
"notificationUrl": url.
"resource": "me/drive/root",
"clientState": "client-specific string",
"expirationDateTime": "2018-01-01T11:23:00.000Z",
I am getting an error like below:
{ error:
{ code: 'InvalidRequest',
message: 'Server could not process subscription creation payload.',
innerError:
{ 'request-id': 'id',
date: '2018-10-16T09:16:46' } } }
I am trying it in my local.
Is there any solution ?
Make sure you post a json request, that means:
Request body is a json string;
'Content-Type' field in headers, and value is 'application/json'
If you use Python, there is a shortcut:
import requests
url = "https://graph.microsoft.com/beta/subscriptions"
headers = {'Authorization': 'Bearer ' + "YOUR_TOKEN"}
data = {
"changeType": "created,updated,deleted",
"notificationUrl": url.
"resource": "me/drive/root",
"clientState": "client-specific string",
"expirationDateTime": "2018-01-01T11:23:00.000Z"
}
resp = requests.post(headers=headers, json=data)
I had the same problem trying the request with Postman. The body was in x-www-form-urlencoded format. It worked when I changed the body format to raw and specified JSON.
Not working "x-www-form-urlencoded" format
Working "raw" format
It looks like MS Graph API only accepts certain input formats. Hope this will help!

How to pass a file to an API from Azure Logic App

I have a simple Logic App. The trigger is on New file (ex: Dropbox, OneNote, etc.)
I want to pass the filename and the fileContent to a API APP (web Api).
But I got error, or worse the content is null once in the API!
The API is in C#.
How do you pass a file (ex: pdf, png) to and API from Logic App
UPDATE:
In Logic App here my action code:
"UploadNewFile": {
"inputs": {
"method": "post",
"queries": {
"filedata": {
"fileName":"#triggerOutputs()['headers']['x-ms-file-name']",
"fileContent":"#base64(triggerBody())"
}
},
"uri": "https://smartuseconnapiapp.azurewebsites.net/api/UploadNewFile"
},
"metadata": {
"apiDefinitionUrl": "https://smartuseconnapiapp.azurewebsites.net/swagger/docs/v1",
"swaggerSource": "website"
},
"runAfter": {},
"type": "Http"
}
In my API App, If the function is declared like this filedata is null
[Route("api/UploadNewFile")]
[HttpPost]
public HttpStatusCode UploadNewFile([FromBody] string filedata)
And if I don't add the [FromBody] like that I got an error.
[Route("api/UploadNewFile")]
[HttpPost]
public HttpStatusCode UploadNewFile(string filedata)
Yes you can send binary content to your own API in a few different methods. Our out-of-the-box actions use this as well.
If you want to send the binary contents as the request body
For example, an outgoing request from the Logic App could have binary content and a content-type header of image/png
In this case the swagger for the body of your request should be binary - or:
{ "name": "body",
"In": "body",
"Schema": {
"Type":"string",
"Format": "binary"
} ... }
That should tell the designer that the request body is binary content. If a previous action or the trigger had binary data (e.g. "When a file is added to FTP") and you used that output in the body, it would show up in your custom API inputs as:
"Body": "#triggerBody()"
Notice there are no { and } on the expression (string interpolations) which would convert the binary content to a string. This would send an outgoing request to the connector with the binary content - so your controller just needs to accept binary content and honor the content-type header as needed.
If you want to send binary content in a JSON request
Sometimes you don't want to send binary as the full request, but as a property of another object. For instance a person object may have a name, address, and profile pic all in the request body. In this case we recommend sending the binary content as base64 encdoded. You can use "format": "base64" in swagger to describe a property as this. In code-view would look something like:
"Body": {
"Name": "#triggerBody()['Name']",
"ProfilePic": "#base64(body('Dropbox'))"
}
Hope that helps. Let me know if you have any questions - here is an article on how logic apps preserves content-types as well.
I found how to to it.
I needed to pass the filename in the querystring and the file in the body of the HTTP Request. Today, it's not possible to do it using the design view so you need to go in code view.
In the Logic App code
"queries": {
"fileName": "#{triggerOutputs()['headers']['x-ms-file-name']}"
},
"body": "#triggerBody()"
In the API App code
public HttpResponseMessage UploadNewFile([FromUri] string fileName)
{
var filebytes = Request.Content.ReadAsByteArrayAsync();
[...]
}
A more detailed explanation can be found in this blog post:
http://www.frankysnotes.com/2017/03/passing-file-from-azure-logic-app-to.html

POST command to WebCeo API

Trying to connect to this WebCEO API.
function getProjects() {
var payload = {
"key": "CUSTOMER_KEY",
"method": "get_projects"
};
payload = JSON.stringify(payload);
var url = "https://online.webceo.com/api/";
var options = {
"method": 'POST',
"contentType" : "application/json",
"payload": payload
};
var response = UrlFetchApp.fetch(url, options);
}
Receiving "Request failed for https://online.webceo.com/api/ returned code 404".
Any hint on what else I need to include / change?
Body must contain the following:
json={"key": "YOUR_API_KEY", "method": "get_projects"}
Well, https://online.webceo.com/api/ does return a 404 when you just try to access it. Did you manage to get that page to not return a 404 error from another client?
Doing so will probably tell you what you're missing here.
However, I'd suspect their API might be having issues.
That's true, you don't make a GET request. You have to send parameters in the body of a POST request. Below is an example in CURL for a situation when you need to get the list of projects:
curl -X POST -d 'json={"key": "YOUR_API_KEY", "method": "get_projects" }' https://online.webceo.com/api/