Python Request POST to PHP - php

I'm trying to submit a form to automate the process of downloading archived data from FIRMS. I've tried inspecting what is being posted using the developer tools as suggested in this response, and the only thing I see being posted is "email" and "cst" (I have no idea what 'cst' is, and it changes each time I refresh the page).
Although I can see the names of the other elements, adding them to the POST request does nothing.
data = {
"region": "custom",
"coord": [llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat],
"source": "MODIS C6",
"fromDate": startDate,
"toDate": endDate,
"output_format": "csv",
"email": "some_email#gmail.com",
}
# submit the request
response = requests.post(
'https://firms.modaps.eosdis.nasa.gov/download/create.php',
data=data)
Thanks for your help!

Related

PHP: I want to know how to send a POST request with everything in this json for my PHP SERVER

This is for my personal sharex imagehost.
{
"Version": "14.1.0",
"Name": "Discord post",
"DestinationType": "ImageUploader",
"RequestMethod": "POST",
"RequestURL": "https://discord.com/api/v9/channels/CHANNEL HERE/messages",
"Headers": {
"authorization": "Discord Token here"
},
"Body": "MultipartFormData",
"Arguments": {
"content": null,
"tts": "false"
},
"FileFormName": "file",
"URL": "{json:['attachments'][0]['url']}",
"ThumbnailURL": "{json:['attachments'][0]['url']}"
}
This json is a sharex custom uploader*
I also want to get a response too.
Please write down the code for me bc im new to php with post requests.
I tried looking at multiple answered questions and I couldn't find one that shows how to use headers and other stuff.
Nevermind, I found out discord rate-limited my website for some reason.

Integration of payments with PayU

I have a problem with integration of payments on PayU .
I am not an advanced programmer , but I want to do this on my website.
I created an sandbox account on the https://www.payu.pl/en .
I was browsing forum but I still don't understand .
First I used this code : https://repl.it/#PayU/pop-up-widget .
But it's probably a combination of the store itself and the website.
Now probably i must use this code and create order from http://developers.payu.com/en/restapi.html#creating_new_order_api
curl -X POST https://secure.snd.payu.com/api/v2_1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer d9a4536e-62ba-4f60-8017-6053211d3f47" \
-d '{
"notifyUrl": "https://your.eshop.com/notify",
"customerIp": "127.0.0.1",
"merchantPosId": "300746",
"description": "RTV market",
"currencyCode": "PLN",
"totalAmount": "21000",
"buyer": {
"email": "john.doe#example.com",
"phone": "654111654",
"firstName": "John",
"lastName": "Doe",
"language": "pl"
},
"settings":{
"invoiceDisabled":"true"
},
"products": [
{
"name": "Wireless Mouse for Laptop",
"unitPrice": "15000",
"quantity": "1"
},
{
"name": "HDMI cable",
"unitPrice": "6000",
"quantity": "1"
}
]
}'
If it's the correct code, how can I use it?
To which format to save this file?
How to run this script.
I have never used curl and I don't know how to go about it.
The code You posted is a command, which will send an HTTP POST-REQUEST (see https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol).
The request basically consists of:
The destination address (https://secure.snd.payu.com/api/v2_1/orders), which identifies the server and the path for the request on the server, such that the server can execute the request appropriately.
Two headers, the first informs, which content type the message has and the second provides some kind of identification / authorization.
The message body itself, which provides the server with the actual content of the request.
This request is executed by means of a terminal command (curl), so to execute it, You have several options. Either, You paste this code exactly like it is show into a terminal to execute it directly, or You save it into a normal text file, which ends on .sh and execute that (after making it executable). These methods of course only work provided You have a unix like operating system and the curl command line utility is in your executable path. However, there are multiply ways of sending an http request, curl is not necessarily needed. There are even some online forms, which allow doing that. Even PayU provides one, which You can find, if You click on the "Try it now" button on the page You just found the command on.
So this answers your questions. However I still have a few remarks:
Is it the correct code? It works, I tested it. But since You created an own sandbox account, You are probably supposed to change the line Authorization: Bearer d9a4536e-62ba-4f60-8017-6053211d3f47, such that it contains the authorization code, which You probably received.
If You want to execute this code on Your website, You need to find out, how to do the request using the language You use for web-developing (e.g. PHP). Then You probably don't need to use curl, but the function in that language using the parts of the request, I pointed out above, appropriately. But that would probably be a new question here.
Make a comment, if You do not understand parts of my answer and I will extend it.

Return a Json file via get request

(ionic 3 app)
let me walk you through, whats going on here.
i have a file information.json, which contains information about various categories.
{
"items": [
{
"name":"Phones and Tablets",
"category_id": "20",
"image": "http://somesite/image/cache/catalog/menu-icons/phone-tablet-icon-500x500.png",
"children": [
{
"name": "Smartphones",
"category_id": "60"
},
{
"name": "Tablets",
"category_id": "62"
},
{
"name": "Accessories",
"category_id": "63"
},
{
"name": "Basic Gsm Phones",
"category_id": "64"
}
]
},
which is just sitting there looking pretty in main directory on my site.
when i maka a get request.
var headers = new Headers();
headers.append('accept', 'application/json');
let options = new RequestOptions({ headers: headers, });
this.http.get("http://somesite/information.json", options)
.map(data => data.json().items)
.subscribe(data => {
this.information = (data);
console.log(this.information);
}
)}
i get CORS error in console.
Failed to load http://somesite/information.json: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
i have a Moesif origin & Cross changer chrome extension, when i enable that then everything works fine in browser.
when i build/run the app on android everything seems to work fine.
but when i run the same app on ios, it doesn't seem to get any response.
i dont know if ios block all CORS by default or something.
i tried fiddling around with .htaccess file of my site, i included
Headers Allow-Access-Control-Origin "*", which seems to work for only 1 request, so i was able to get categories information. but all other get requests from my app became invalid. currently i am looking around to set up a PHP file with headers information so when i make a get request to php, it echos out that file information.json , but the problem is i just dont know how to set it up properly.
if you guys have any other solution for this problem, feels free to share them.
thanks.

Submitting a POST request to Piwik.php

I'm trying to send bulk requests to the Piwik tracking api (/piwik.php) and I'm running into a problem. When I send the request (from a PHP script over ajax, curl and from fiddler2), I'm receiving the following:
Debug enabled - Input parameters:<br/>array ( )
token_auth is authenticated!
Loading plugins: { Provider,Goals,UserCountry }
Current datetime: 2013-05-02 16:02:27
The request is invalid: empty request, or maybe tracking is disabled in the config.ini.php via record_statistics=0
My post looks like this:
{"requests":["%3Fidsite%3D1%26url%3Dhttp%3A%2F%2Fexample.org%26action_name%3DTest+bulk+log+Pageview%26rec%3D1"],"token_auth":"mytokenhere"}
Which is the example straight from their website. I've made sure to set the content-type to "Content-Type: application/json" and that my configuration has record_statistics = 1 explicitly defined.
According to the documentation, this should all work, but I'm still getting the empty request. The import_logs.py script also works, so I know that the general bulk importing is not broken, but I'm not sure how to get the program to accept my data. Has anyone had any luck with it?
Thanks!
Perhaps the problem with your request is that your query strings are URL encoded, but they don't need to be since they're part of the POST body.
Your POST should be like this instead:
{"requests":["?idsite=1&url=http://example.org&action_name=Test+bulk+log+Pageview&rec=1"],"token_auth":"mytokenhere"}
See the example at the docs for the Bulk Tracking API: http://piwik.org/docs/tracking-api/reference/#toc-advanced-bulk-tracking-requests
Figured out what was wrong. Their documentation was incorrect in how the request needed to be formatted. First, URL Encoded data was unnecessary. Second, the JSON string needs to look like this:
{
"requests": [
{
"apiv": "1",
"bots": "1",
"idsite": "1",
"download": "",
"cdt": "",
"dp": "",
"url": "",
"urlref": "",
"cip": "",
"ua": "",
"_cvar": {
"1": [
"Not-Bot",
"Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_5;+en-US)+AppleWebKit/534.10+(KHTML,+like+Gecko)+Chrome/8.0.552.231+Safari/534.10"
]
},
"rec": "1"
}
]
}
Not all of those pieces of data need to be sent, but that's the format necessary. After that it's just data cleansing.

Modifying User-Attribute on SharePoint data item using HTTP

I'm using the (JSON) HTTP interface to communicate with SharePoint. The communication itself is done via cURL and a convinience-wrapper in PHP. Problems arise, when I want to push data to SP.
Since I'm no Microsoft / SharePoint guy, I'm missing the proper vocabulary to explain my needs. I'll therefore demonstrate using data I received from SharePoint.
GET http://example.org/mytest/_vti_bin/listdata.svc/Aufgaben(2) returns the following (truncated by me) data:
{
"d" : {
"__metadata": {
"uri": "http://example.org/mytest/_vti_bin/listdata.svc/Aufgaben(2)",
"etag": "W/\"5\"",
"type": "Microsoft.SharePoint.DataService.AufgabenItem"
},
"ID": 2,
"InhaltstypID": "0x010800821BC29B80192B4C960A688416597526",
"Inhaltstyp": "Aufgabe",
"Titel": "Neuer Titel",
"ZugewiesenAn": {
"__deferred": {
"uri": "http://example.org/mytest/_vti_bin/listdata.svc/Aufgaben(2)/ZugewiesenAn"
}
},
"ZugewiesenAnId": 29,
"F\u00e4lligkeitsdatum": "\/Date(1323993600000)\/"
}
}
"ZugewiesenAn" is a user. If I query the deferred values, I get (truncated by me, again)
{
"d" : {
"__metadata": {
"uri": "http://example.org/mytest/_vti_bin/listdata.svc/Benutzerinformationsliste(29)",
"etag": "W/\"1\"",
"type": "Microsoft.SharePoint.DataService.BenutzerinformationslisteItem"
},
"InhaltstypID": "0x010A000719C31710976A48867763D86F6586E0",
"Name": "Rehm Rodney",
"Konto": "EXT\\rodney.rehm",
"ID": 29,
"Inhaltstyp": "Person",
}
}
So I can see that the value of "ZugewiesenAn" should be "EXT\rodney.rehm" (as I need the username). Thus far, no problem.
The question is how I create a new or update an existing object with a different user for "ZugewiesenAn" (a User/Group field)?
I've tried:
Sending the username as the value of "ZugewiesenAn" or "ZugewiesenAnId" results in a Bad Request.
Querying http://example.org/_vti_bin/People.asmx (SOAP: SearchPrincipals) only yields numeric IDs for people that have actually worked with the list. If I query a username that hasn't logged into that SharePoint list before, I get ID -1.
I could not find out how to add users to the userlist via REST. You can, however, use the SOAP ResolvePrincipal request (example) - which does the job!
I am not a SharePoint guy and focus mostly on REST and OData. But think that REST OData API for SharePoint follows common rules for REST OData.
Common rules for REST and OData is to use different HTTP verbs for different operations. Read, create, update, and delete operations are mapped directly to GET, POST, PUT, and DELETE HTTP verbs.
So, you are getting your user by GET HTTP verb on URI http://example.org/mytest/_vti_bin/listdata.svc/Benutzerinformationsliste(29)
To delete this user use verb DELETE on the same URI and user id with empty HTTP message body.
To create user HTTP verb POST, same URI and json in message body. Also while creating ID shouldn't be specified (except situations when ID isn't auto-incremented in databases). Content-Type for HTTP message should be set: application/json for JSON.
The same situation with update - PUT, same URI
http://example.org/mytest/_vti_bin/listdata.svc/Benutzerinformationsliste(29)
and json in HTTP message body with content-type:application/json.
Format of json should be the same as you've received.
{
"InhaltstypID": "0x010A000719C31710976A48867763D86F6586E0",
"Name": "Rehm Rodney",
"Konto": "EXT\\rodney.rehm",
"ID": 29,
"Inhaltstyp": "Person",
}

Categories