I have been trying to replace email address in email header, but can't seem to accomplish what I wanted.
TO="abc#ghi.com,def#xyz.com"
bash-3.2$ cat mail-pre-tmp.txt
From: xbn#abc.com
To: vxxx#aaa.com,yyy#bbbb.com
MIME-Version: 1.0
Content-Type: text/html;
Subject: email results
bash-3.2$ `sed "s,To:.*$,To: '"${TO}"',g"` mail-pre-tmp.txt
sed: -e expression #1, char 33: unknown option to `s'
Expecting to replace "TO:" to variable set to, so expected:
From: xbn#abc.com
To: abc#ghi.com,def#xyz.com
MIME-Version: 1.0
Content-Type: text/html;
Subject: email results
It's
sed "s/To:.*$/To: "${TO}"/g" < mail-pre-tmp.txt
with / not ,
Related
So I'm trying to do a comparison and it just happens to be that the value I'm checking for has the same name as a command on the computer with is a problem.
This is the command i run.
if $current_branch != "HEAD"; then echo '1'; fi;
And here is the result as you can see the HEAD program ran.
400 URL must be absolute
Content-Type: text/plain
Client-Date: Thu, 01 Mar 2018 16:45:48 GMT
Client-Warning: Internal response
200 OK
Cache-Control: no-store, no-cache, must-revalidate, max-age=0
Connection: keep-alive
Date: Thu, 1 Mar 2018 16:45:49 GMT
Server: PWS/8.3.1.0.8
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Access-Control-Allow-Origin: https://www.head.com
Client-Date: Thu, 01 Mar 2018 16:45:49 GMT
Client-Peer: 151.249.91.221:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 High Assurance Server CA
Client-SSL-Cert-Subject: /C=US/ST=California/L=Campbell/O=CDNetworks Inc./CN=support2.cdnetworks.net
Client-SSL-Cipher: ECDHE-RSA-AES256-SHA
Client-SSL-Socket-Class: IO::Socket::SSL
Content-Security-Policy: frame-ancestors 'self' https://head.testing-varnish.symmetrics.de
Set-Cookie: geoip=IC; expires=Sat, 31-Mar-2018 16:45:49 GMT; Max-Age=2592000; path=/; domain=head.com
Set-Cookie: lang=en; expires=Sat, 31-Mar-2018 16:45:49 GMT; Max-Age=2592000; path=/; domain=head.com
Set-Cookie: currentLangId=1; expires=Sat, 31-Mar-2018 16:45:49 GMT; Max-Age=2592000; path=/; domain=head.com
Set-Cookie: root=1; expires=Sat, 31-Mar-2018 16:45:49 GMT; Max-Age=2592000; path=/; domain=head.com
X-Frame-Options: SAMEORIGIN
X-Px: nc h0-s42.p1-arn ( h0-s4012.p6-lhr>CONN), nc h0-s4012.p6-lhr ( h0-s4102.p11-fra), nc h0-s4102.p11-fra ( origin)
So how do i avoid this from happening and not have command collide with the string value i want to compare?
The argument to if is always a command. You are probably looking for the special command [ (aka test) which compares strings.
if [ "$current_branch" != "HEAD" ]; then
echo '1'
fi
Take note of the requirement to have spaces on both sides of the [ and ] tokens, and the requirement to quote strings which might contain shell metacharacters.
Depending on whether you require pre-POSIX compatibility, you might also want to invert the negation. On the other hand, in modern shells like Bash and Ksh, you probably want to use the replacement [[ which is somewhat more robust and versatile.
The requirement to have a terminating ] for symmetry is purely aesthetic, but still a requirement. It's pretty quirky that the original Bourne shell didn't have string comparison features built into the shell itself, but, well, this is what we ended up with.
As an aside, if your example is representative of your actual code, you might want to use the somewhat more parsimonious shorthand syntax
[ "$current_branch" = "HEAD" ] || echo '1'
Using spray-json on an Akka HTTP server; how can I "assume Content-type: application/json" for requests when not supplied?
Issue
curl localhost:12345/request -d'{"sample":"json"}'
doesn't work unless I add
-H "Content-type: application/json"
explicitly.
Why I ask
not ideal for showing succint examples on a README.md
annoying to add the header manually all the time while debugging
You should have defined you API to accept content-type json only, thats why it does not accept other content-types.
Just doing curl -XPOST -d 'content' URL will post your content as application/x-www-form-urlencoded (default behaviour).
See --verbose of curl POST, see Content-Type in example below
$ curl -XPOST -d '{"test" : "testValue"}' "https://jsonplaceholder.typicode.com/posts" -v
* Trying 104.31.87.157...
* Connected to jsonplaceholder.typicode.com (104.31.87.157) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificate: sni233425.cloudflaressl.com
* Server certificate: COMODO ECC Domain Validation Secure Server CA 2
* Server certificate: COMODO ECC Certification Authority
* Server certificate: AddTrust External CA Root
> POST /posts HTTP/1.1
> Host: jsonplaceholder.typicode.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 22
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 22 out of 22 bytes
< HTTP/1.1 201 Created
< Date: Sat, 18 Mar 2017 04:54:41 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 51
< Connection: keep-alive
< Set-Cookie: __cfduid=d91d0ebbaa5f7b40a998d327ffce2b5671489812881; expires=Sun, 18-Mar-18 04:54:41 GMT; path=/; domain=.typicode.com; HttpOnly
< X-Powered-By: Express
< Vary: Origin, X-HTTP-Method-Override, Accept-Encoding
< Access-Control-Allow-Credentials: true
< Cache-Control: no-cache
< Pragma: no-cache
< Expires: -1
< X-Content-Type-Options: nosniff
< Etag: W/"33-cwlRczABGtsoiZUP8lw9WSIt684"
< Via: 1.1 vegur
< Server: cloudflare-nginx
< CF-RAY: 3415986bb9f50c35-SEA
<
{
"{\"test\" : \"testValue\"}": "",
"id": 101
* Connection #0 to host jsonplaceholder.typicode.com left intact
}
You have to change your client headers to match what the API server accepts.
$ curl -H "Content-type: application/json" -XPOST -d '{"test" : "testValue"}' "https://jsonplaceholder.typicode.com/posts" -v
* Trying 104.31.87.157...
* Connected to jsonplaceholder.typicode.com (104.31.87.157) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificate: sni233425.cloudflaressl.com
* Server certificate: COMODO ECC Domain Validation Secure Server CA 2
* Server certificate: COMODO ECC Certification Authority
* Server certificate: AddTrust External CA Root
> POST /posts HTTP/1.1
> Host: jsonplaceholder.typicode.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-type: application/json
> Content-Length: 22
>
* upload completely sent off: 22 out of 22 bytes
< HTTP/1.1 201 Created
< Date: Sat, 18 Mar 2017 04:53:22 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 38
< Connection: keep-alive
< Set-Cookie: __cfduid=d8e90de27fc1fa87fb42b763a4199ba7d1489812801; expires=Sun, 18-Mar-18 04:53:21 GMT; path=/; domain=.typicode.com; HttpOnly
< X-Powered-By: Express
< Vary: Origin, X-HTTP-Method-Override, Accept-Encoding
< Access-Control-Allow-Credentials: true
< Cache-Control: no-cache
< Pragma: no-cache
< Expires: -1
< X-Content-Type-Options: nosniff
< Etag: W/"26-Zx6VPi+rfbM5YFlBzT2pzGEHcgg"
< Via: 1.1 vegur
< Server: cloudflare-nginx
< CF-RAY: 3415967b2af12a19-SEA
<
{
"test": "testValue",
"id": 101
* Connection #0 to host jsonplaceholder.typicode.com left intact
}
You can change the content-type on you server, and change whatever content you receive to JSON by yourself (which might not a good idea though)
I am building an EC site, where my customers can pay through PayPal API. Now, I am learning how it works, using Sandbox; referring to this page: https://developer.paypal.com/docs/integration/direct/billing-plans/
I have succeeded the prerequisites, i.e., having created a PayPal app,
gotten an access token, and made an API call. And then, I have succeeded making a billing plan, copying-and-pasting the sample command on the page, just replacing the Access Token.
Now, I want to activate the billing plan, but couldn't have succeeded.
The command used is, once again, copied-and-pasted from the page, as below.
curl -v -k -X PATCH https://api.sandbox.paypal.com/v1/payments/billing-plans/P-7DC96732KA7763723UOPKETA/ \
-H 'X-PAYPAL-OAUTH-CONTEXT: {"consumer":{"accountNumber":1181198218909172527,"merchantId":"5KW8F2FXKX5HA"},"merchant":{"accountNumber":1659371090107732880,"merchantId":"2J6QB8YJQSJRJ"},"apiCaller":{"clientId":"AdtlNBDhgmQWi2xk6edqJVKklPFyDWxtyKuXuyVT-OgdnnKpAVsbKHgvqHHP","appId":"APP-6DV794347V142302B","payerId":"2J6QB8YJQSJRJ","accountNumber":"1659371090107732880"},"scopes":["https://api.paypal.com/v1/payments/.*","https://uri.paypal.com/services/payments/futurepayments","openid"]}' \
-H 'Content-Type: application/json' \
-d '[{
"op": "replace",
"path": "/",
"value": {
"state": "ACTIVE"
}
}]'
First, as instructed, I just replaced the Plan ID "P-7DC96732KA7763723UOPKETA" with mine, provided in the previous response for creating the plan.
* Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: api.sandbox.paypal.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> PATCH /v1/payments/billing-plans/P-8AX21799EN516221GJMBOECA/ HTTP/1.1
> Host: api.sandbox.paypal.com
> User-Agent: curl/7.43.0
> Accept: */*
> X-PAYPAL-OAUTH-CONTEXT: {"consumer":{"accountNumber":1181198218909172527,"merchantId":"5KW8F2FXKX5HA"},"merchant":{"accountNumber":1659371090107732880,"merchantId":"2J6QB8YJQSJRJ"},"apiCaller":{"clientId":"AdtlNBDhgmQWi2xk6edqJVKklPFyDWxtyKuXuyVT-OgdnnKpAVsbKHgvqHHP","appId":"APP-6DV794347V142302B","payerId":"2J6QB8YJQSJRJ","accountNumber":"1659371090107732880"},"scopes":["ttps://api.paypal.com/v1/payments/.*","ttps://uri.paypal.com/services/payments/futurepayments","openid"]}
> Content-Type: application/json
> Content-Length: 78
>
* upload completely sent off: 78 out of 78 bytes
< HTTP/1.1 401 Unauthorized
< Date: Fri, 17 Feb 2017 12:18:47 GMT
< Server: Apache
< paypal-debug-id: c46e304b4bb46
< Paypal-Debug-Id: c46e304b4bb46
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D669689432%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Fri, 17 Feb 2017 12:48:47 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Content-Length: 0
< Connection: close
< Content-Type: text/plain; charset=ISO-8859-1
<
* Closing connection 0
And I tried with some other parameter replacements, like the Client ID, but no luck.
Do I need to replace other parameters?
Or, have I done something wrong?
SOLVED.
On this page, I found simpler and more straightforward command
and made up below:
curl -v -X PATCH https://api.sandbox.paypal.com/v1/payments/billing-plans/<Plan ID>/ \
-H "Content-Type:application/json" \
-H "Authorization: Bearer <Access Token>" \
-d '[
{
"path":"/",
"value":{"state":"ACTIVE"},
"op":"replace"}
]'
Got the response as below:
* Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: api.sandbox.paypal.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> GET /v1/payments/billing-plans/<Plan ID> HTTP/1.1
> Host: api.sandbox.paypal.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type:application/json
> Authorization: Bearer <Access Token>
>
< HTTP/1.1 200 OK
< Date: Sun, 19 Feb 2017 11:36:50 GMT
< Server: Apache
< paypal-debug-id: 3ca31778e271e
< Content-Language: *
< Paypal-Debug-Id: 3ca31778e271e
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D1384360280%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Sun, 19 Feb 2017 12:06:52 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Vary: Authorization
< Content-Length: 1391
< Connection: close
< Content-Type: application/json
<
* Closing connection 0
{"id":"<Plan ID>","state":"ACTIVE","name":"Sample Plan",
...
"rel":"self","method":"GET"}]}
Got HTTP 200 and the state "ACTIVE".
Thanks for your trying to help, many thanks!
I am trying to make a POST request to my locally running rest endpoint as follows:
curl -X POST -d '[{"name":"xyz","cost":"10"}]' http://localhost:8080/xyz/rest/abc --header "Content-Type: application/json"
this results in
Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream#3180b68d; line: 1, column: 2]
When I use other tool for eg. RESTClient plugin in Firefox browser I get an expected response for this post body from my rest endpoint.
Well I enabled server side logging of the request at my Jersey rest endpoint:
The RESTClient request results in:
15:48:31,916 INFO [org.glassfish.jersey.filter.LoggingFilter] (http--127.0.0.1-
8080-1) 1 * Server has received a request on thread http--127.0.0.1-8080-1
1 > POST http://localhost:8080/xyz/rest/abc
1 > accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
1 > accept-encoding: gzip, deflate
1 > accept-language: null
1 > cache-control: no-cache
1 > connection: keep-alive
1 > content-length: 91
1 > content-type: application/json; charset=UTF-8
1 > host: localhost:8080
1 > pragma: no-cache
1 > user-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Fire
fox/40.0
15:48:32,086 INFO [org.glassfish.jersey.filter.LoggingFilter] (http--127.0.0.1-
8080-1) 1 * Server responded with a response on thread http--127.0.0.1-8080-1
1 < 201
1 < Content-Type: application/json
The cURL request results in:
15:49:04,786 INFO [org.glassfish.jersey.filter.LoggingFilter] (http--127.0.0.1-
8080-2) 2 * Server has received a request on thread http--127.0.0.1-8080-2
2 > POST http://localhost:8080/xyz/rest/abc
2 > accept: application/json
2 > content-length: 76
2 > content-type: application/json
2 > host: localhost:8080
2 > user-agent: curl/7.33.0
15:49:04,792 INFO [org.glassfish.jersey.filter.LoggingFilter] (http--127.0.0.1-
8080-2) 2 * Server responded with a response on thread http--127.0.0.1-8080-2
2 < 400
2 < Content-Type: text/plain
Now, I know my rest endpoint works correcty, Just curious as to why this is happening for cURL request. Any suggestions are welcome.
OK so the problem is that I am using a windows machine and so single quote around the data is causing this issue.
To get it to work i had to use double quotes around the data and escape the double quotes within the data.
curl -X POST -d "[{\"name\":\"xyz\",\"cost\":\"10\"}]" http://localhost:8080/xyz/rest/abc --header "Content-Type: application/json"
I'm trying to filter invoices that I'm getting using QuickBook IPP and PHP devkit, but for some reason, quickbooks keeps sending back an empty result. My code is below:
$query = '<ContactIdSet><Id>340</Id></ContactIdSet>';
$invoices = $invoiceService->findAll($quickbooks->Context, $quickbooks->creds['qb_realm'], $query, 1, 999);
With this code, my request (minus Oauth info) is:
POST https://services.intuit.com/sb/invoice/v2/538361885 HTTP/1.1
Content-Type: text/xml
Authorization: OAuth realm="", oauth_signature_method="HMAC-SHA1", oauth_signature="", oauth_nonce="GAmtH", oauth_timestamp="1366692972", oauth_token="", oauth_consumer_key="", oauth_version="1.0"
Content-Length: 298
<?xml version="1.0" encoding="UTF-8"?>
<InvoiceQuery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.intuit.com/sb/cdm/v2">
<StartPage>1</StartPage>
<ChunkSize>999</ChunkSize>
<ContactIdSet>
<Id>340</Id>
</ContactIdSet>
</InvoiceQuery>
but even though there are invoices under that customer id, the response has no invoices:
HTTP/1.1 200 OK
Date: Tue, 23 Apr 2013 05:06:39 GMT
Server: Apache/2.2.22 (Unix)
ContextInitTime: 9
Response-Id: cb8b6eaa-f810-4fad-9f69-3485f400680d
IdRestateTime: 4
HeaderQueryTime: 4
Content-Encoding: gzip
HeaderDAOTime: 4
Response-App-Time: 62
Response-Routing-Time: 67
Content-Length: 133
Connection: close
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><RestResponse xmlns="http://www.intuit.com/sb/cdm/v2"><Invoices/></RestResponse>
Any ideas as to why quickbooks won't return the invoices that are associated with that customer?
Here is the XML response that shows the invoice exists when I use ->findAll()
HTTP/1.1 200 OK
Date: Tue, 23 Apr 2013 17:44:02 GMT
Server: Apache/2.2.22 (Unix)
LineQueryTime: 35
ContextInitTime: 94
Response-Id: 9b3d4e46-a6b5-4f90-81f4-3c42b0462330
AssemblingTime: 0
HeaderQueryTime: 91
Content-Encoding: gzip
HeaderDAOTime: 91
LineDAOTime: 35
Response-App-Time: 271
Response-Routing-Time: 276
Content-Length: 930
Connection: close
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><RestResponse xmlns="http://www.intuit.com/sb/cdm/v2"><Invoices><Invoice><Id idDomain="NG">681891</Id><SyncToken>3</SyncToken><MetaData><CreateTime>2013-04-18T03:13:26.796Z</CreateTime><LastUpdatedTime>2013-04-23T03:49:05.800Z</LastUpdatedTime></MetaData><ExternalKey idDomain="QB">1189</ExternalKey><Synchronized>true</Synchronized><Header><DocNumber>WEB000126</DocNumber><TxnDate>2013-02-28T00:00:00Z</TxnDate><Status>Paid</Status><CustomerId idDomain="QB">340</CustomerId><CustomerName>Test, Ray & Teryl</CustomerName><RemitToId idDomain="QB">340</RemitToId><RemitToName>Test, Ray & Teryl</RemitToName><ShipDate>2013-02-28T00:00:00Z</ShipDate><SubTotalAmt>375</SubTotalAmt><TaxRate>0</TaxRate><TaxAmt>0</TaxAmt><TotalAmt>375</TotalAmt><ToBePrinted>true</ToBePrinted><ToBeEmailed>false</ToBeEmailed><ARAccountId idDomain="QB">64</ARAccountId><ARAccountName>Accounts Receivable</ARAccountName><SalesTermId idDomain="QB">8</SalesTermId><SalesTermName>Due on 1st</SalesTermName><DueDate>2013-03-01T00:00:00Z</DueDate><BillAddr><Id idDomain="QB">00000000000001cg</Id><Line1>Ray & Teryl Test</Line1><Line2>3290 Test Test</Line2><City>Stone Mountain</City><CountrySubDivisionCode>GA</CountrySubDivisionCode><PostalCode>30087</PostalCode><Default>true</Default><Tag>Billing</Tag></BillAddr><ShipAddr><Id idDomain="QB">00000000000003rW</Id><Default>false</Default><Tag>Shipping</Tag></ShipAddr><BillEmail>Test#Test.com</BillEmail><Balance>0</Balance></Header><Line><Id idDomain="QB">1191</Id><Desc>Conservatory Registration Fee</Desc><Amount>125</Amount><Taxable>false</Taxable><ItemId idDomain="QB">14</ItemId><ItemName>Artios Conservatory</ItemName><ItemType>Service</ItemType><UnitPrice>125</UnitPrice><Qty>1</Qty><SalesTaxCodeId idDomain="QB">2</SalesTaxCodeId><SalesTaxCodeName>Non</SalesTaxCodeName></Line><Line><Id idDomain="QB">1192</Id><Desc>Preparatory Registration Fee</Desc><Amount>125</Amount><Taxable>false</Taxable><ItemId idDomain="QB">142</ItemId><ItemName>Elem Prep Reg (5/1-8/31)</ItemName><ItemType>Service</ItemType><UnitPrice>125</UnitPrice><Qty>1</Qty><SalesTaxCodeId idDomain="QB">2</SalesTaxCodeId><SalesTaxCodeName>Non</SalesTaxCodeName></Line><Line><Id idDomain="QB">1193</Id><Desc>Preparatory Registration Fee</Desc><Amount>125</Amount><Taxable>false</Taxable><ItemId idDomain="QB">142</ItemId><ItemName>Elem Prep Reg (5/1-8/31)</ItemName><ItemType>Service</ItemType><UnitPrice>125</UnitPrice><Qty>1</Qty><SalesTaxCodeId idDomain="QB">2</SalesTaxCodeId><SalesTaxCodeName>Non</SalesTaxCodeName></Line><Line><Id idDomain="QB">1194</Id><Desc>PayPal Convenience Fee</Desc></Line></Invoice></Invoices></RestResponse>
To add an answer for the question, there is no support for that specific filter in v2 of the API.
You'll need to filter within your application
thanks
Jarred