Bash script - cURL with variables - bash

I'm trying to get a cURL script to input my variables in a --data section. I'm fairly new to this, but it's just inserting the variables names.
The background is this script is called to hit an API in our ticketing system to create a new job. I am finding the ticket that is created has the subject "${DESCRIPTION}" and not "problem description".
#!/bin/bash
# This will log a ticket in Ticketing System
DESCRIPTION='Problem Description'
SUBJECT='Problem Subject'
curl --location --request POST 'https://XXXXX.domain.com/helpdesk/tickets.json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
--data '{
"helpdesk_ticket":
{
"description": "${DESCRIPTION}",
"subject": "${SUBJECT}",
"email": "email#domain.com",
"priority": 1,
"status": 2
},
"cc_emails": ""
}'

As per always, got this working just after I posted....
The solution was to wrap the variable in "'".
#!/bin/bash
# This will log a ticket in Ticketing System
DESCRIPTION='Problem Description'
SUBJECT='Problem Subject'
curl --location --request POST 'https://XXXXX.domain.com/helpdesk/tickets.json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
--data '{
"helpdesk_ticket":
{
"description": "'"$DESCRIPTION"'",
"subject": "'"$SUBJECT"'",
"email": "email#domain.com",
"priority": 1,
"status": 2
},
"cc_emails": ""
}'

Related

curl: 400 Bad Request. The browser (or proxy) sent a request that this server could not understand

I'm getting "400 Bad Request. The browser (or proxy) sent a request that this server could not understand." for the curl command. Curl command is as below, can someone please help?
token=jfkdjfdikdjydve83hhd54rsfdghsghktwhdh87
payload_file=test_fortify_scan.zip
curl -X POST https://dnsname/api/scan \
-H "authorization: Bearer $token" \
-H 'content-type: application/json' \
-d '{"projVer": "dev", "language": "java",
"payloadFile":"$payload_file", "emailList": "myemail#mail.com"}'
Looks like quotes problem. Look at Using curl POST with variables defined in bash script functions
token="jfkdjfdikdjydve83hhd54rsfdghsghktwhdh87"
payload_file="test_fortify_scan.zip"
curl -X POST https://dnsname/api/scan \
-H "authorization: Bearer $token" \
-H 'content-type: application/json' \
-d '{"projVer": "dev", "language": "java",
"payloadFile":"'"$payload_file"'", "emailList": "myemail#mail.com"}'

Checkout.com returns error invalid payment currency

I'm working on the Checkout.com API integration for golang.
I chose checkout.com for several alternative providers like Sofort and iDEAL. There are a good documentation for both of them:
Sofort
iDEAL
but code from the example returns the same error
curl https://sandbox.checkout.com/api2/v2/tokens/payment \
-H "Authorization: sk_test_..." \
-H "Content-Type: application/json" \
-X POST \
-d '{
"email" : "test#email.com",
"value": 1000,
"currency": "EUR",
"chargeMode": "3",
"successUrl": "http://mycustomerurl.com/order?result=pass",
"failUrl": "http://mycustomerurl.com/order?result=fail"
}'
returns
{"id":"pay_tok_7A0B43FF-C418-4C54-811D-704279BB5AAA","liveMode":false}
after this payment token is used for
curl https://sandbox.checkout.com/api2/v2/charges/localpayment \
-H "Authorization: sk_test_..." \
-H "Content-Type: application/json" \
-X POST \
-d '{
"email" : "test#email.com",
"localPayment" : {
"lppId" : "lpp_14",
"userData" : {}
},
"paymentToken" : "pay_tok_7A0B43FF-C418-4C54-811D-704279BB5AAA"
}'
and here we are
{"errorCode":"81001","message":"Invalid payment currency","eventId":"11e5a092-425e-4db9-910e-f26024a0e007"}
To be able to test alternative payment methods these methods would need to be enabled on your Checkout.com Sandbox account. Only card payments are enabled by default.
To do so you need to get in touch with Checkout.com's support team and they will do the required configuration on your account.

Can I define an object as a variable in a shell script?

I know how to store a string as a variable, for example: API="http://localhost:4741"
However, for the sake of a CURL request I would like to be able to store on object as a variable that I can access values on, something like OBJ="{name : Joe}". Is this possible?
Right now my CURL request looks like this:
curl --include --request POST localhost:3000/scrape \
--header "Content-Type: application/json" \
--data '{
"url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
"team": "LA Clippers"
}'
I would like to be able to do something like this, using a dictionary or an object:
TEAM=( ["Clippers"]="http://www.oddsshark.com/stats/gamelog/basketball/nba/20736" )
curl --include --request POST localhost:3000/scrape \
--header "Content-Type: application/json" \
--data '{
"url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
"team": "${TEAM[Clippers]}"
}'

GCM response results is not having "Not Registered IDS" list

I am using curl to send push notifications using GCM. Here it is as follows:
curl --header 'Authorization: key=myAPiKey' --header 'Content-Type: application/json' https://android.googleapis.com/gcm/send -d '{"registration_ids":["registration_ids"], "collapse_key": "Turn", "data": { "title": "fdsfdsfsdfd","body": "fdsf dsf sd fsd fds fds fds", "badge": "1" , "content_available": 1 ,"url": "#/app/home"} }'
In reposnse I am getting as :
{"multicast_id":7729772425353298779,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"}]}
I am not getting registration_ids that are not registered. How Can I do this. I want this in curl only as i am using ruby 1.8.6 application.
Please help me on this

rest api openam add user parametrised

hello I have this script in bash:
first part : authentication against server - works fine.
second part: adds user - and this works fine when I define user directly in curl code - but when I want to add user from parameters.. then I got a message error:
"{"code":400,"reason":"Bad Request","message":"The request could not
be processed because the provided content is not valid
JSON","detail":"Unexpected character ('$' (code 36)): expected a valid
value (number, String, array, object, 'true', 'false' or 'null')\n at
[Source: org.apache.catalina.connector.CoyoteInputStream#3a248e6a;
line: 2, column: 18]"}"
Any ideas how can I pass values to this script ? :)
Regards
#!/bin/bash
adm_user="admin"
adm_pass="secret"
user_name=""
user_pass=""
auth_url="http://url/OpenAM-11.0.0/json/authenticate"
add_user_url="http://url/OpenAM-11.0.0/json/users/?_action=create"
session_id=$(curl \
--request POST --header "X-OpenAM-Username: $adm_user " \
--header "X-OpenAM-Password: $adm_pass" \
--header "Content-Type: application/json" \
--data "{}" $auth_url | cut -d"\"" -f4 )
sleep 1
curl \
--request POST \
--header "iplanetDirectoryPro: $session_id" \
--header "Content-Type: application/json" \
--data \
'{
"username": "$1",
"userpassword": "secret12",
"mail": "bjensen#example.com"
}' \
$add_user_url
OK, mates I got the answer:
'{
"username": "'"$1"'",
"userpassword": "'"$2"'" ,
"mail": "bjensen#example.com"
}' \

Resources