How to pass variables as input to SOAP webservice from command line - bash

I have a Soap web service to which I need to pass input as username and password to get the response. I am able to get the response from command line (Linux) if I hardcode the values with the below command.
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:ACTION_YOU_WANT_TO_CALL" --data #FILE_NAME URL_OF_THE_SERVICE
(FILE_NAME is basically my web service with hardcoded values of username and password)
But I don't want to hardcode any values and wanted to pass them as a parameters. Is there any way I can get the response from web service from command line by passing parameters to the web service?

Write a wrapper script, which 'generates' the output file with the substituted variables.

Related

How can I pass username and password in invoke http processor

How can I pass username and
Password in invoke http processor. ( I am invoking this nifi-api/token to generate token ) it’s required username and password to authorise .
I am passing username and password in request username and request password. But still it’s not working
When you want to generate a token for the NiFi API for it to be used in subsequent API calls of NiFi you need to pass the credentials as x-www-form-urlencoded.
This can be achieved like this using a cURL command
curl --location --request POST 'https://server_URL/nifi-api/access/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=<USER_NAME>' \
--data-urlencode 'password=<PASSWORD>'
If you are familiar with Postman then you can use the Body tab and select x-www-form-urlencoded and define the credentials as Key and Value pair. This would generate you the token for the NiFi.

Cannot access Azure DevOps API using PAT in cURL command in Bash script

I have a script that uses the Azure DevOps API to retrieve every work item in a query. Then it retrieves the metadata for each work item. It requires a PAT. Until today the PAT has worked. I believe it is expired. I created a new PAT, but every attempt to retrieve the same information is unauthorized (401).
The cURL command in my script that worked until now:
ado_token={username#company.com:PAT, all Base-64 encoded as one string}
curl -X GET -H "Authorization: Basic $ado_token" -H 'Cache-Control: no-cache' "https://dev.azure.com/{company}/{project}/_apis/wit/wiql/{query ID}?api-version=5.1"
Here are the facts:
Going to the URL directly in the browser succeeds.
The new token is in the same project as the URL.
The new token has full access.
Microsoft documentation on ADO PATs provides this example:
curl -u username[:{personalaccesstoken}] https://dev.azure.com/{organization}/_apis/build-release/builds
However, when my username and PAT are entered with a URL I know to be correct, it is unauthorized.
Both in the format of the Microsoft example and the URL I would like to use in my script, these are all unauthorized in all iterations of Bearer and Basic. The URL used works in the browser:
{username}:{PAT}
{username}#{company}.com:{PAT}
Base-64 encoded {PAT}
Base-64 encoded {username}#{company}.com:{PAT}
Base-64 encoded pat:{PAT}
Base-64 encoded {username}:{PAT}
Base-64 encoded {username}#{company}.com:{PAT}
I have tried both in the command line and Postman but no added information was provided.
Am I missing something obvious? The most confusing aspect of this is that the previous PAT worked in this same code. Thank you for any help.
Try the command below:
curl -u :{PAT} 'https://dev.azure.com/{company}/{project}/_apis/wit/wiql/{query ID}?api-version=5.1'
In the -u parameter the Username field must be blank and the PAT is the original string.
Thus the command would be in the following format:
curl -u :lplnqn4l4glwqkslsfel7t2wjevfi5tayuiwm772qeawbwo3ztua 'https://dev.azure.com/acme/projetx/_apis/wit/wiql/6cbbddb4-f752-453b-9f98-f523470826fe?api-version=5.1'
Postman
using Authorization without username: Choose Basic Auth. and enter the PAT as password.
using Headers: Use key as Authorization and value as Basic {Base-64 encoded pat{:PAT}}. Note that {:PAT} needs to be base64 encoded
Curl
using basic authentication without username: curl -u :{PAT} https://dev.azure.com/{org}/_apis/projects
using headers: curl -H 'Authorization: Basic {Base-64 encoded pat{:PAT}}'
https://dev.azure.com/{org}/_apis/projects

Flock webhook token

I am trying to create webhook as per this document and this doesn't include any clue about where does the token comes from.
https://docs.flock.com/display/flockos/Create+An+Incoming+Webhook
My curl command as below
curl -X POST -H "Content-Type: application/json" https://api.flock.com/hooks/sendMessage/guid-guid -d '{"text": "This is a test message.","token":"test"}'
Error message:
{"error":"InvalidParameter","description":"A required parameter for the method call is missing or invalid","parameter":"token"}
Can someone point me what's missing here.
Flock gives you the token for the webhook when you finish adding a new one at https://dev.flock.com/webhooks
You can look it up again when you're done by going to the edit option for the webhook you've added; at the moment the token is given at the bottom of the page:
Webhook URL
Send your JSON payload to this URL
[your-token-here]

Curl command not uploading file contents

Hi I am using cURL command to upload a file which is a POST request to my local machine service.
I am using following commands to upload
curl -i -X POST -H "Content-Type: multipart/form-data" -F
"/Users/myName/Folder/file.csv" http://localhost:port/api/fileupload
In my application side I am using spring frameworks web binding to receive the file
Following is the code snippet
public ResponseEntity importDimensions(#RequestBody MultipartFile file) {
// file is variable is always null
}
What am I missing here?
You need an # sign before the filename, like this: #/Users/myName/Folder/file.csv.
And if your server-side code is expecting a parameter named file then you need to do this:
-F "file=#/Users/myName/Folder/file.csv"

Curl post requests with Spotify client id & secret return invalid client

I'm following Spotify's client credentials authorization flow, but all of my curl requests are returning {"error":"invalid_client"} each time. Here are the instructions from Spotify:
The request will include parameters in the request body:
grant_type - Set to “client_credentials”.
The header of this POST request must contain the following parameter:
Authorization - A Base 64 encoded string that contains the client ID and client secret key. The field must have the format: Authorization: Basic <base64 encoded client_id:client_secret>
They also include an example of a curl request:
$ curl -H "Authorization: Basic ZjM4ZjAw...WY0MzE=" -d grant_type=client_credentials https://accounts.spotify.com/api/token
Following their example, so far I've tried curl requests with:
client_id and client_secret plain
both base64 encoded seperately
only one or the other encoded
both encoded as one string with the colon
both encoded as one string without the colon
each of the above with a regenerated client secret
I'm using Ruby's Base64#encode64 method to encode. Still no luck. Any helpful hints?
Okay, I got it working - passing my client_id and client_secret, separated by a colon, to Base64.strict_encode64 (NOT Base64.encode64) and then passing that to the above curl request gets a 200 response with an access token. Apparently encode64 was not enough.
I ran into this error when I ran the curl command in my terminal.
-bash: unexpected EOF while looking for matching `"'
Solved by using single quotes instead of double quotes.

Resources