How can i make GET request with this kind of API's on Sim800 - http

I can do single line GET requests with sim800 but I couldn't understand to use this API.
curl --request GET \
--url 'https://api.collectapi.com/pray/all?data.city=istanbul' \
--header 'authorization: apikey 3tXXXMYAPIKEYq9:1RxvCMYAPIKEYgAG' \
--header 'content-type: application/json'
It shows me how to use it with curl but I can't understand how can I make this as single line on Sim800

AT+HTTPINIT<\r><\r><\n>OK<\r><\n>
AT+HTTPPARA="CID",1<\r><\r><\n>OK<\r><\n>
AT+HTTPPARA="URL","https://api.collectapi.com/pray/all?data.city=kahramanmaras"<\r><\r><\n>OK<\r><\n>
AT+HTTPPARA="USERDATA","authorization: apikey 3tvAtuSxxxxxx4zDlq9:1RxvC4fQTxxxxxGbgAG"<\r><\r><\n>OK<\r><\n>
AT+HTTPPARA="CONTENT","application/json"<\r><\r><\n>OK<\r><\n>
AT+HTTPACTION=0<\r><\r><\n>OK<\r><\n>
<\r><\n>
+HTTPACTION: 0,603,0<\r>
I'm doing something wrong but I don't understand :(

Try the at+httpread command to find out what is the error is it looks like a custom error rather than a HTTP error

Related

How to use multiple double quotes in a udev rule

I am trying to send a post request once a usb device is connected to the Pi using udev rules.
My first idea was that the udev rules should look like this:
SUBSYSTEM=="tty", ATTRS{serial}=="GT633DNJ", RUN+="curl --header "Content-Type: application/json" --request POST --data '{"name":"boardname"}' http://0.0.0.0:8080/post"
An error was produced in the syslog once I connected the usb device to the py and documented in the syslog
Feb 16 16:02:24 localhost systemd-udevd[204]: invalid key/value pair in file /etc/udev/rules.d/60-board.rules on line 3, starting at character 193 ('C')
which I guess means that it has considered the RUN part to look like this
RUN+="curl --header " and it didn't know what to do with the rest of the line
Content-Type: application/json" --request POST --data '{"name":"boardname"}' http://0.0.0.0:8080/post"
I tried also to escape the double quotes with a \ like this:
SUBSYSTEM=="tty", ATTRS{serial}=="GT633DNJ", RUN+="curl --header \"Content-Type: application/json\" --request POST --data '{\"name\":\"saf85xx_03\", \"helper_host\":\"'hostname'\"}' http://0.0.0.0:8080/post"
But it didn't work neither
Is it possible to send the post request from inside the RUN without having to put the curl request in a bash script and call the script from inside RUN?

Linkedin new Post API - 403 error / Field Value validation failed

Trying to use the new POST API from linkedin, to get all the posts for an organization described in the doc here
Both CURL and HTTP requests gives me a 403 with the following message "Field Value validation failed in PARAMETER: Data Processing Exception while processing fields [/author]"
curl -X GET 'https://api.linkedin.com/rest/posts?author=urn%3Ali%3Aorganization%$XXXXX&isDsc=false&q=author&count=10' \
-H 'X-Restli-Protocol-Version: 2.0.0' \
-H 'LinkedIn-Version: 202210' \
-H 'X-RestLi-Method: FINDER' \
-H 'Authorization: Bearer {TOKEN}'
Tried to remove the X-Restli-Protocol-Version header as per this thread, but didn't help much.
Thanks in advance !

Linkedin Api sample AdSupplyForecast does not work

Nowadays I am working on Linkedin AdSupplyForecast api to follow at the below reference,
https://learn.microsoft.com/en-us/linkedin/marketing/integrations/ads/advertising-targeting/ad-supply-forecasts#find-supply-by-criteriav2
However the sample code does not work also I can not find any extra description about criteriaV2.
Standart Api sample at the below and response is '{"message":"Invalid HTTP Request","status":404}'
curl -H "Authorization:Bearer XX" -H "Content-Type:application/json" "https://api.linkedin.com/v2/adSupplyForecasts?q=criteriaV2&account=urn%3Ali%3AsponsoredAccount%3A518121035&timeRange=(start: 1587639976000,end: 1589540776000)&campaignType=SPONSORED_UPDATES&competingBid=(bidType:CPM,bidPrice:(currencyCode:USD,amount:10))&targetingCriteria=(include:(and:List((or:(urn%3Ali%3AadTargetingFacet%3Alocations:List(urn%3Ali%3AcountryGroup%3ANA))))),exclude:(or:(urn%3Ali%3AadTargetingFacet%3AstaffCountRanges:List(urn%3Ali%3AstaffCountRange%3A%2810001%2C2147483647%29))))"
I modified it and like as at the below but it send server error '{"message":"Internal Server Error","status":500}', would you share with me a correct sample of it ?
curl --location --request GET 'https://api.linkedin.com/v2/adSupplyForecasts?q=criteriaV2&account=urn:li:sponsoredAccount:518121035&timeRange.start=1587639976000&timeRange.end=1589540776000&campaignType=SPONSORED_UPDATES&targetingCriteria.include=and:List%28%28or:%28{encoded%20urn:li:adTargetingFacet:locations}:List%28{encoded%20urn:li:countryGroup:NA}%29%29%29%29&targetingCriteria.exclude=or:%28{encoded%20urn:li:adTargetingFacet:staffCountRanges}:List%28{encoded%20urn:li:staffCountRange:%2810001,2147483647%29}%29%29' \ --header 'Authorization: XXX'

Activate KAA configuration using Server REST APIs

I used kaa rest api for activate my configuration (using Postman), but i have no idea how to fill Parameter content type of configurationId . I have try
{
"id" : "98593",
"applicationId": "32769",
"schemaId": "65544" ,
"endpointGroupId": "98308"}
but I get HTTP/1.1 400 Bad Request, any suggestion will be appreciated.
Thanks
finally i can solve this problem,
You need to set your content-type to application/json and POST body just fill with configuration id
curl -v -S -u username:password -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '12423' 'http://localhost:8080/kaaAdmin/rest/api/activateConfiguration' | python -mjson.tool

Curl-convert to a simple http request?

I have some curl request, in which i would like to build from it a basic POST request-authenticated (with headers etc), i couldn't find any tool that convert that :
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxx/Calls.json' \
--data-urlencode 'To=xxxxxxx65542' \
--data-urlencode 'From=+xxxxxxx4215' \
-d 'Url=https://api.twilio.com/2010-04-01' \
-d 'Method=GET' \
-d 'FallbackMethod=GET' \
-d 'StatusCallbackMethod=GET' \
-d 'Record=false' \
-u ACbe68cddxxxxxxxxxxxx3aba243cc4cdb:0f442xxxxxxxxxxxxxxxxxxx
So how would my POST request should look like ?
Okay so i was trying to figure out how to send a text message from an ESP8266 nodeMcu v0.9 module. It is capable of working like an arduino with the arduino ide 1.6.4.
Anyways, I found http://textbelt.com and it only shows a simple CURL way of sending the text message.
This is the CURL message it wants you to send
$ curl -X POST http://textbelt.com/text \ -d number=5551234567 \ -d "message=I sent this message for free with textbelt.com"
So to convert to a normal HTTP POST command i did the following. (this works in Arduino IDE)
number and message are String objects.
String messageToSend = "number="+number+"&message="+message;
client.print("POST /text HTTP/1.1\r\n");
client.print("Host: textbelt.com\r\n");
client.print("Content-Type: application/x-www-form-urlencoded\r\n");
client.print("Content-Length: ");
client.print(messageToSend.length());
client.print("\r\n\r\n");
client.print(messageToSend);
At first i tried without the Content-Type but that didn't seem to work. So i had to add the type of content i was sending as well.
If you were to monitor the network traffic with say WireShark you would see
POST /text HTTP/1.1\r\n
Host: textbelt.com\r\n
Content-Type: application/x-www-form-urlencoded\r\n
Content-Length: 48\r\n
\r\n
number=5551234567&message=this is a text message
I may have been able to use less text with text/plain as the content-type but i think it may need the application urlencoded type to work.
Hope this helps someone else trying to convert curl to http.
From the cURL man page :
-H, --header (HTTP) Extra header to use when getting a web page. You may specify any number of extra headers. Note that if you
should add a custom header that has the same name as one of the
internal ones curl would use, your externally set header will be
used instead of the internal one. This allows you to make even
trickier stuff than curl would nor‐ mally do. You should not replace
internally set headers without knowing perfectly well what you're
doing. Remove an internal header by giving a replacement without
content on the right side of the colon, as in: -H "Host:". If you send
the custom header with no-value then its header must be terminated
with a semicolon, such as -H "X-Custom- Header;" to send
"X-Custom-Header:".
curl will make sure that each header you add/replace is sent with the
proper end-of-line marker, you should thus not add that as a part of
the header content: do not add newlines or carriage returns, they will
only mess things up for you.
See also the -A, --user-agent and -e, --referer options.
This option can be used multiple times to add/replace/remove multiple
headers.
Amazon AWS makes heavy use of headers for authentication. A quick Google should lead to many examples such as this one from http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash :
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/${file}
All you need to do is adapt the AWS examples for your twilio use.
To make the example into a POST, just change PUT to POST and add your POST fields -d "field1=val1&field2=val2&field3=val3"
You can specify the headers using --header and the type of request (POST) by using -X / --request parameters.
Example:
curl --request POST --header "X-MyHeader: MyAuthenticatedHeader" www.stackoverflow.com
In your case it should be:
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxx/Calls.json' \
--header 'X-MyHeader: MyAuthenticatedHeader' \
--data-urlencode 'To=xxxxxxx65542' \
--data-urlencode 'From=+xxxxxxx4215' \
-d 'Url=https://api.twilio.com/2010-04-01' \
-d 'Method=GET' \
-d 'FallbackMethod=GET' \
-d 'StatusCallbackMethod=GET' \
-d 'Record=false' \
-u ACbe68cddxxxxxxxxxxxx3aba243cc4cdb:0f442xxxxxxxxxxxxxxxxxxx

Resources