I know that curl can post data to a URL:
$ curl -X POST http://httpbin.org/post -d "hello"
{
"args": {},
"data": "",
"files": {},
"form": {
"hello": ""
},
"headers": {
"Accept": "*/*",
"Content-Length": "5",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "curl/7.50.1"
},
"json": null,
"origin": "64.238.132.14",
"url": "http://httpbin.org/post"
}
And I know I can pipe to curl to achieve the same thing:
$ echo "hello" | curl -X POST http://httpbin.org/post -d #-
{
"args": {},
"data": "",
"files": {},
"form": {
"hello": ""
},
"headers": {
"Accept": "*/*",
"Content-Length": "5",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "curl/7.50.1"
},
"json": null,
"origin": "64.238.132.14",
"url": "http://httpbin.org/post"
}
Now here is where it gets tricky. I know about http transfer-coding and chunking, for example to send a multiline file:
('silly' is a file that contains several lines of text, as seen here)
$ cat silly | curl -X POST --header "Transfer-Encoding: chunked" "http://httpbin.org/post" --data-binary #-
{
"args": {},
"data": "",
"files": {},
"form": {
"hello\nthere\nthis is a multiple line\nfile\n": ""
},
"headers": {
"Accept": "*/*",
"Content-Length": "41",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "curl/7.50.1"
},
"json": null,
"origin": "64.238.132.14",
"url": "http://httpbin.org/post"
}
Now what I want to be able to do is to have curl read a line from stdin, send it as a chunk, and then come back and read stdin again (which allows me to keep it going continously). This was my first attempt:
curl -X POST --header "Transfer-Encoding: chunked" "http://httpbin.org/post" -d #-
And it does work ONE TIME ONLY when I hit ctrl-D, but that obviously ends the execution of curl.
Is there any way to tell curl "Send (using chunk encoding) what I've given you so far, and then come back to stdin for more" ?
Thanks so much, I've been scratching my head for a while on this one!
Related
I am trying to populating an empty field by using patch method in Contentful. The following piece of code works in one cloned environment but does not work in another.
let patchData: OpPatch[] = [
{
op: 'replace',
path: '/fields/keywords',
value: entryKeyword,
},
];
await cmaClient.entry.patch({ entryId: entryId }, patchData, { 'X-Contentful-Version': entryVersion });
When I try to execute this, receiving a 'Unprocessable Entity' error:
UnprocessableEntity: {
"status": 422,
"statusText": "Unprocessable Entity",
"message": "Could not apply patch to entry: invalid patch",
"details": {},
"request": {
"url": "/spaces/xyz/environments/abc/entries/123456789",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json-patch+json",
"X-Contentful-User-Agent": "sdk contentful-management-plain.js/7.54.2;",
"Authorization": "Bearer ...",
"user-agent": "node.js/v14.19.2",
"Accept-Encoding": "gzip",
"X-Contentful-Version": 25,
"Content-Length": 78
},
"method": "patch",
"payloadData": "[{\"op\":\"replace\",\"path\":\"/fields/keywords\",\"value\":\"test keyword\"}]"
},
"requestId": "abcd-123456"
}
I have the same exact access permissions to both environments. What am I missing out on?
I had the same issue - turned out when the entry doesn't have the filed you're trying to patch - it will throw an error like above.
I've been trying to follow the docs at MessageBird to test out sending a verification SMS. But when I execute the curl command, the returned response is as expected here:
{"id":"e41c509641a34324a0e1333a4e87d84d","href":"https://rest.messagebird.com/verify/e41c509641a34324a0e1333a4e87d84d","recipient":447000000000,"originator":"+447000000000","type":"sms","reference":null,"messages":{"href":"https://rest.messagebird.com/messages/d18f22ae466g4c349799404d878c9815","id":"d18f22ae466g4c349799404d878c9815"},"status":"sent","createdDatetime":"2021-11-11T15:19:01+00:00","validUntilDatetime":"2021-11-11T15:19:31+00:00"}
But, if you open up the href link from the response it gives the following error:
{"errors":[{"code":20,"description":"message not found","parameter":null}]}
This is the curl request that I use:
curl --location --request POST 'https://rest.messagebird.com/verify' --header 'Authorization: AccessKey ACCESS_KEY' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'recipient=+447000000000' --data-urlencode 'originator=07000000000'
Make sure that you are using a Live key and not the Test key, as the Test environment does not store any of your requests.
If you are looking for a sample response to work with, here is one I just got back:
GET https://rest.messagebird.com/verify/<VID>
{
"id": "<VID>",
"href": "https://rest.messagebird.com/verify/<VID>",
"recipient": 27830000000,
"originator": "Code",
"type": "sms",
"reference": null,
"messages": {
"href": "https://rest.messagebird.com/messages/<MID>",
"id": "<MID>"
},
"status": "sent",
"createdDatetime": "2021-11-11T16:25:06+00:00",
"validUntilDatetime": "2021-11-11T16:25:36+00:00"
}
GET https://rest.messagebird.com/messages/<MID>
{
"id": "<MID>",
"href": "https://rest.messagebird.com/messages/<MID>",
"direction": "mt",
"type": "sms",
"originator": "Code",
"body": "",
"reference": null,
"validity": null,
"gateway": 10,
"typeDetails": {
"verify": true
},
"datacoding": "plain",
"mclass": 1,
"scheduledDatetime": null,
"createdDatetime": "2021-11-11T16:25:07+00:00",
"recipients": {
"totalCount": 1,
"totalSentCount": 1,
"totalDeliveredCount": 1,
"totalDeliveryFailedCount": 0,
"items": [
{
"recipient": 27830000000,
"originator": null,
"status": "delivered",
"statusDatetime": "2021-11-11T16:25:14+00:00",
"recipientCountry": "South Africa",
"recipientCountryPrefix": 27,
"recipientOperator": "",
"messageLength": 20,
"statusReason": "successfully delivered",
"price": {
"amount": 0.021,
"currency": "EUR"
},
"mccmnc": "65507",
"mcc": "655",
"mnc": "07",
"messagePartCount": 1
}
]
}
}
I would like to use Power Automate to add a user in as a member to a SharePoint Site using HTTP request.
The flow continues to fail on me and I'm wondering if anyone managed to do this successfully in the past?
I got the Group ID from :
https://{org name}.sharepoint.com/sites/{site name}/_api/web/id
I have attached included the input and output of the HTTP Request (within flow) below
Raw Inputs
{
"host": {
"connectionReferenceName": "shared_sharepointonline",
"operationId": "HttpRequest"
},
"parameters": {
"dataset": "https://{REDACTED}.sharepoint.com/",
"parameters/method": "POST",
"parameters/uri": "_api/web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users",
"parameters/headers": {
"accept": "application/json;odata.metadata=none",
"content-type": "application/json"
},
"parameters/body": "{'LoginName':'i:0#.f|membership|{REDACTED}#{REDACTED}.com'}"
}
}
Raw Outputs
{
"statusCode": 400,
"headers": {
"Pragma": "no-cache",
"x-ms-request-id": "cb6ab59f-909a-2000-ac2f-2217e416179a",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Cache-Control": "no-store, no-cache",
"Set-Cookie": "{REDACTED};Path=/;HttpOnly;Secure;Domain=sharepointonline-we.azconn-we.p.azurewebsites.net,ARRAffinitySameSite={REDACTED}24;Path=/;HttpOnly;SameSite=None;Secure;Domain=sharepointonline-we.azconn-we.p.azurewebsites.net",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"Date": "{TIME & DATE}",
"Content-Length": "457",
"Content-Type": "application/json",
"Expires": "-1"
},
"body": {
"status": 400,
"message": "The expression \"web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users\" is not valid.\r\nclientRequestId: 1cc16a39-7d9c-4290-b07d-4c7329611fb8\r\nserviceRequestId: cb6ab59f-909a-2000-ac2f-2217e416179a",
"source": "https://{REDACTED}.sharepoint.com/_api/web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users",
"errors": [
"-1",
"Microsoft.SharePoint.Client.InvalidClientQueryException"
]
}
}
The error I get is:
"The expression "web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users" is not valid.
clientRequestId: 1cc16a39-7d9c-4290-b07d-4c7329611fb8
serviceRequestId: cb6ab59f-909a-2000-ac2f-2217e416179a"
This makes me think the group ID is incorrect. Can someone please advise if this is incorrect or if I have maybe formatted the uri incorrectly?
Try to use the body like this:
{
'__metadata': {
// Type that you are modifying.
'type': 'SP.User'
},
'LoginName': '<<User Login Name>>'
}
I have integrated my k8s deployment with google endpoints. I have 12 services out of which 11 services are working fine with google endpoints except for one service. When its transferring requests to application container its ignoring the header values with underscore.
Implementation
I have added this in my application deployment (Ignore syntax i have it in correct format in deployment)
- args:
- --http_port
- "8081"
- --backend
- 127.0.0.1:8080
- --service
- <MY_ENDPOINT>
- --service_account_key
- /etc/nginx/creds/<MY_CREDS>
- --rollout_strategy=managed
image: gcr.io/endpoints-release/endpoints-runtime:1
imagePullPolicy: Always
name: esp
ports:
- containerPort: 8081
protocol: TCP
resources: {}
volumeMounts:
- mountPath: /etc/nginx/creds
name: service-account-creds
readOnly: true
Here in the below sample, i have sent two headers with TEST-CODE and TEST_CODE. Both are getting received at the application end when i am sending request via application port, but when i access it via esp port, i receive only header with -(hyphen) not with _(underscore). TEST-CODE is being received in the server but not TEST_CODE, when accessing via esp.
When i am sending request to my application using curl or postman via 8080 which is application port
curl -XPOST http://localhost:8080/<CONTEXT_PATH> -H "Content-Type: application/json" -H "USER-ID: abc" -H "TEST-CODE: xyz" -H "TEST_CODE: wxyz"
I get response like this
{
"timestamp": "2020-04-05T19:42:44.958564Z",
"principal": null,
"session": null,
"request": {
"method": "POST",
"uri": "http://localhost:8080/<MY_URL>",
"headers": {
"host": [
"localhost:8080"
],
"test-code": [
"xyz"
],
"content-type": [
"application/json"
],
"x-user-id": [
"abc"
],
"test_code": [
"wxyz"
],
"user-agent": [
"curl/7.52.1"
],
"accept": [
"*/*"
]
},
"remoteAddress": null
},
"response": {
"status": 200,
"headers": {
"Content-Length": [
"435"
],
"Date": [
"Sun, 05 Apr 2020 19:42:45 GMT"
],
"Content-Type": [
"application/json;charset=UTF-8"
]
}
},
"timeTaken": 633
}
When i am sending request to my application using curl or postman via 8081 which is via esp
curl -XPOST http://localhost:8081/<CONTEXT_PATH>?key=<MY_KEY> -H "Content-Type: application/json" -H "USER-ID: abc" -H "TEST-CODE: xyz" -H "TEST_CODE: wxyz"
I get response like this
{
"timestamp": "2020-04-05T19:42:57.102184Z",
"principal": null,
"session": null,
"request": {
"method": "POST",
"uri": "http://localhost/<MY_URL>?<MY_KEY>",
"headers": {
"x-real-ip": [
"127.0.0.1"
],
"x-google-real-ip": [
"127.0.0.1"
],
"x-cloud-trace-context": [
"<MY_GOOGLE_TRACE_CONTEXT>"
],
"host": [
"localhost"
],
"test-code": [
"xyz"
],
"x-endpoint-api-project-id": [
"<MY_ENDPOINT_PROJECT_ID>"
],
"content-type": [
"application/json"
],
"x-forwarded-for": [
"127.0.0.1"
],
"x-user-id": [
"abc"
],
"user-agent": [
"curl/7.52.1"
],
"accept": [
"*/*"
]
},
"remoteAddress": null
},
"response": {
"status": 400,
"headers": {
"Connection": [
"close"
],
"Content-Length": [
"256"
],
"Date": [
"Sun, 05 Apr 2020 19:42:57 GMT"
],
"Content-Type": [
"application/json"
]
}
},
"timeTaken": 21
}
Again,
Notice the difference : I am sending test code header as TEST-CODE and TEST_CODE, both are coming when i am accessing via application port, but when i am accessing via esp container, the application is receiving TEST-CODE alone, not TEST_CODE.
I have tried some other HEADERS with -(hyphen) and some with _(underscore). Every time headers with -(hyphen) is being received via esp to application but not with _(underscore).
I have took the above responses from spring actuator endpoints (actuator/httptrace)
Can someone help?
I used below method to get Auth-token and i got the output as below.But if use that id as Auth-token for PUT method it's not working it's showing as explained below.
curl -sd '{"auth":{"passwordCredentials":{"username": "admin", "password": "password"}}}' -H "Content-type: application/json" http://169.0.0.11:5000/v2.0/tokens | python -m json.tool
{
"access": {
"metadata": {
"is_admin": 0,
"roles": []
},
"serviceCatalog": [],
"token": {
"audit_ids": [
"GgpxHyihQVyuI1ryerQZVw"
],
"expires": "2016-08-15T16:11:49Z",
"id": "bcced26a96304e8197fa85e110df9aa2",
"issued_at": "2016-08-15T15:11:49.386446"
},
"user": {
"id": "a5064af3b125449a9a09e9b69966f843",
"name": "admin",
"roles": [],
"roles_links": [],
"username": "admin"
}
}
}
curl -i -X PUT "X-Auth-Token:bcced26a96304e8197fa85e110df9aa2" http://169.0.0.11/dashboard/project/containers/test/mymusic/
but its saying that Could not resolve host: X-AUTH-TOKEN HTTP/1.1 301 MOVED PERMANENTLY
can any one help me to solve this problem please.
I believe you have missed to add -H for Header, rest looks fine.
curl -i -X PUT -H "X-Auth-Token:bcced26a96304e8197fa85e110df9aa2" http://169.0.0.11/dashboard/project/containers/test/mymusic/