Add default headers for every request in httpie - httpie

I need to be able to either set in my httpie/config.json file to include some default headers (these are custom headers and not normal ones) to every request that i send from httpie by default (ALWAYS)
ie:
headers examples
http "http://poopskiesuprise.com" 'CUSTOM_HEADER:asdf' 'HEADER_TWO:asdf'
always include the 'CUSTOM_HEADER' and 'HEADER_TWO'
to every request so i can just do this
http "http://poopskiesuprise.com"
i did not see a good way to do this in the documentation so any help would be great!

The easiest solution is creating a session with desired headers, and using it on your config.json:
Create a session (for your desired host):
$ http --session ./session.json pie.dev/get X-Custom-Header:value X-Custom-Header2:value2
and then add this to your config (~/.config/httpie/config.json on POSIX):
{
"default_options": [
"--session-read-only=/path/to/session.json"
]
}
and then from now on, every request will add those two headers:
$ http pie.dev/get
{
"args": {},
"headers": {
"X-Custom-Header": "value",
"X-Custom-Header2": "value2"
},
"url": "http://pie.dev/get"
}
Unless you unset them:
$ http pie.dev/get X-Custom-Header:
{
"args": {},
"headers": {
"X-Custom-Header2": "value2"
},
"url": "http://pie.dev/get"
}

Related

Why is the Azure Devops API telling me that I must have these parameters for my Push request when I already do?

I'm trying to make a Git push request to our Azure Devops server via the API. The address is https://MYSITE.visualstudio.com/MYPROJECT/_apis/git/repositories/2b34d4f7-2c1f-42e7-8861-u0ba34f72b40/pushes?api-version=5.1 and the body is as follows:
{
"commits": [
{
"comment": "Just a dummy commit",
"changes": [
{
"changeType": "edit",
"item": {
"path": "/src/MYPROJECT/MYPROJECT.csproj"
},
"newContent": {
"content": "beans",
"contentType": "rawText"
}
}
]
}
],
"refUpdates": [
{
"name": "refs/heads/TestDummyPRs/upgradeProjectToLatest",
"oldObjectId": "058da4f3328cb1048cb43faf3b5158bc3b025615"
}
]
}
I'm getting the following error:
Web Request Failed after 4 attempts. Request: https://MYSITE.visualstudio.com/MYPROJECT/_apis/git/repositories/2b34d4f7-2c1f-42e7-8861-u0ba34f72b40/pushes?api-version=5.1. Status: BadRequest. Response: Invalid status code [BadRequest]. Response: {"$id":"1","innerException":null,"message":"The parameters are incorrect. A posted push must contain exactly one commit and one refUpdate.\r\nParameter name: newPush","typeName":"Microsoft.TeamFoundation.SourceControl.WebServer.InvalidArgumentValueException, Microsoft.TeamFoundation.SourceControl.WebServer","typeKey":"InvalidArgumentValueException","errorCode":0,"eventId":0}
"A posted push must contain exactly one commit and one refUpdate" doesn't seem entirely reasonable as that's exactly what I have in my body. Does anybody know what might be going on here?
Note that I am having no issues making other web requests, such as creating branches or retrieving file contents.
I expected my web request to proceed smoothly, and to create a Push containing the specified commit to the specified refUpdate.
I have made a manual push for via the Azure Devops web interface and caught the network traffic, and I grabbed the following JSON request out of it:
{
"commits": [
{
"changes": [
{
"changeType": 2,
"item": {
"path": "/src/MYPROJECT/MYPROJECT.csproj"
},
"newContent": {
"content": "beans",
"contentType": 0
}
}
],
"comment": "Just a dummy commit"
}
],
"refUpdates": [
{
"name": ""refs/heads/TestDummyPRs/upgradeProjectToLatest",
"oldObjectId": "058da4f3328cb1048cb43faf3b5158bc3b025615"
}
]
}
This seems to be meaningfully identical to the Push I'm making from my code, other than the enum fields using numerical values instead of text. I have tried my code with numerical values for enums, but that didn't change anything about the error.
I found the issue. The web request from my application was being sent with UTF-16 encoding, whereas Postman had defaulted to UTF-8 encoding. I changed my application to use UTF-8 and it worked.

Create subscription with URL including Bearer Token in the header

Hello FIWARE specialists,
I like to create a subscription, which pushes notifications to an external service.
The external service needs authorization with a barrier token.
If I use curl, I add "--header 'Authorization: Bearer XXX'".
How can I add a barrier token to the subscription request?
"notification": {
"attributes": [ "id", "type", "name", "location", "occupancy"],
"format": "normalized",
"endpoint": {
"uri": "http://a.b.c.de:1111",
"accept": "application/json"
}
},
Is there an option to add a header field to the "endpoint" setup in the subscription like:
"headers": "Authorization: Bearer XXX"
Hopefully, you can help me in that case.
Thanks, Knigge
In Orion Context Broker using the NGSIv2 API you can use custom notifications to achieve that. For example the following subscription:
...
"httpCustom": {
"url": "http://context-provider:3000/subscription/low-stock-store001",
"headers": {
"Authorization": "Bearer XXX"
}
}

How to edit the apple-app-site-association file auto-generated by Firebase Dynamic Links?

Whenever I create a new url prefix using free Google-provided domain (for example, yourapp.page.link). The apple-app-site-association file gets automatically created at the respective https://yourapp.page.link/apple-app-site-association and https://yourapp.page.link/.well-known/apple-app-site-association.
The generated apple-app-site-association file looks something like:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "1234567890.com.example.ios",
"paths": [
"NOT /_/*",
"/*"
]
}
]
}
}
and it is redirecting all paths to my app.
I want to exclude certain paths that should not be handled by my app. I know I can do this by specifying “NOT ” in front of the path that i want to exclude in the paths array, but I just can't find a way to edit the auto-generated file.
I had a similar issue with dynamic links "hijacking" the links for email verification and password reset, forcing me to manually add exclude paths to the apple-app-site-association file. The only way forward I could find that seems to be working is to do the following:
Add your apple-app-site-association file to your public folder:
/public/apple-app-site-association (or whatever you have set as public folder)
/public/.well-known/apple-app-site-association
Add the following to the hosting section in your firebase.json (keep "appAssociation": "AUTO" or your dynamic links will stop working and you'll see an error message in the console.)
"headers": [
{
"source": "/.well-known/apple-app-site-association",
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
]
},
{
"source": "/apple-app-site-association",
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
]
}
]

Is there any way to pass response object values from first request to second request as input parameters in graph batch request

Is there any way to pass response object values from first request to second request as input parameters in graph batch request (2nd request is dependant on 1st request - graph/json-batching)
In the following request, the client is specifying that requests 1 should be run first, then request 2.
2nd Request need the id from the 1st Request's response as URL variable. What is the way to achieve it?
JSON
{
"requests": [
{
"id": "1",
"method": "GET",
"url": "/users/<upn>?$select=id"
},
{
"id": "2",
"dependsOn": [ "1" ],
"method": "GET",
"URL": "users/<id from the 1st request>/presence"
}
]
}
Yes, As #Tiny-wa said this is not possible as of now. There is already a feature request raised in the Microsoft Graph Feedback Forum, please upvote it so that the product team may implement it in future.
So, for now you need to make two separate requests, make first request and get response details and use it and make a second request.

Azure Logic App returns 404 with valid Project Online ODATA query using /_api/Projectdata

I want to filter and select Project Online data using Enterprise Custom Fields (ECF) in an Azure Logic App. I start with the out-of-the-box Project Online connector to trigger on project publish, then list project and task details.
Using the default connector, I can return project data but it does not contain the ECF data. Looking at the generated code, the Project Online connector uses /_api/ProjectServer. If I make similar requests (outside of Logic Apps) using /_api/Projectdata I get the ECF data.
If I edit the Logic App code with modified URL and fields, I get a 404 error. There seems to be something missing that I cannot see when I make the request with the modified values from within the Logic App.
My guess is the connector is limiting access to /_api/Projectdata (though the trigger itself is using this URL).
The following returns the data I want if I request it straight from the browser:
https://tenant.sharepoint.com/sites/PWA/_api/Projectdata/Projects(guid'project_GUID')
This is the raw input in the logic app:
{
"host": {
"connection": {
"name": "/subscriptions/subscription_GUID/resourceGroups/MyRG/providers/Microsoft.Web/connections/projectonline-1"
}
},
"method": "get",
"path": "/_api/Projectdata/Projects(guid'project_GUID')",
"queries": {
"siteUrl": "https://tenant.sharepoint.com/sites/PWA"
}
}
This is the raw output of the error:
{
"statusCode": 404,
"headers": {
"Access-Control-Allow-Methods": "GET, PUT, PATCH, DELETE, POST",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "3600",
"Access-Control-Expose-Headers": "*",
"Date": "Thu, 20 Sep 2018 16:58:42 GMT",
"Content-Length": "54",
"Content-Type": "application/json"
},
"body": {
"statusCode": 404,
"message": "Resource not found"
}
}
URLs and GUID have been modified in the examples above.

Resources