Curl request not working using php script - php

I have curl using voxbone API action method pass "did_dropdown" parameter value to get country wise dids. But another thing I am passing action method "didlist_type_city" parameter value not any response with pass country.
Note : Get url is working on terminal command line but postman api not any response get
curl -u xxxxx:xxxxx -H "Content-type: application/json" -H "Accept: application/json" "https://sandbox.voxbone.com/ws-voxbone/services/rest/inventory/did?didIds='xxxxxx'&pageNumber=0&pageSize=1&countryCodeA3=IND"

Related

How to Post data from external HTML form to Eloqua Form using cURL

I want to post data from an external HTML form to a simple form created in Eloqua, using cURL method. I tried to follow this documentation but I am not able to post data to Eloqua.
When I try from command line (Windows) -
curl --user "usercreds" --header "Content-Type: application/json" --request POST --data "{"testfirstname":"abc","testlastname":"def","singleCheckbox":1}" https://secure.p0{POD Number}.eloqua.com/api/REST/1.0/data/form/{formid}
I get below error:
[{"type":"ObjectValidationError","property":"fieldValues","requirement":{"type":"NoDuplicatesRequirement"},"value":""}]
When I try from PHP, as mentioned here https://www.eehelp.com/question/using-curl-to-repost-to-eloqua-data/
or https://github.com/fredsakr/eloqua-php-request the curl returns HTTP code 0.
This is a simple form created in Eloqua without any validations.
I do not know what I am doing wrong here.

Set a curl header for getting tokens

I want to set a header for getting the token from flipkart. I dont know how to set a header in curl. My header should like
curl -u <appid>:<app-secret> https://sandbox-api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api
It looks like you're trying to do HTTP basic authentication, or at least that's what the -u option of curl does when used alone like this.
In PHP you would set up basic authentication for a curl request like this, assuming $ch is your curl instance (which you can get with curl_init):
curl_setopt($ch, CURLOPT_USERPWD, 'appid:appsecret');
See the curl documentation on curl_setopt for more information.
In curl command you have to do like this,
curl -u your-app-id:your-app-token https://sandbox-api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api
you will get the result like this on success,
{"access_token":"394b7d-418a-43f6-8fd5-e67aea2c4b","token_type":"bearer","expires_in":4657653,"scope":"Seller_Api"}
by using this token you can make further api call's like for example listing api,
curl -H "Authorization:Bearer your-access-token" -H "Content-Type: application/json" -d 'json-here-see-format-in-api-example' https://url-end-point-refer-api-docs
note: you have to create app id and secret in "https://sandbox-api.flipkart.net/oauth-register/login" for sandbox. Don't store the access token it will get expired in certain period of time.
link for api doc's - "https://seller.flipkart.com/api-docs/fmsapi_index.html"

Smartsheet API error when using curl to update column picklist values

Good Morning,
I'm looking for a way to update the dropdown values in a column in my Smartsheet. Going off the Smartsheet API 2.0, I managed to come up with the following code to use with curl, but I'm getting the following error when running it in CMD.
Here is the code I'm using:
curl https://api.smartsheet.com/2.0/sheets/7654838910642052/columns/4 -H "Authorization: Bearer 6cn0otb4tdjueqzuflgnkzff17" -X PUT -d '{"title":"Weekend Date","index":4, "type" : "PICKLIST", "options" :["31-OCT-2015"]}' -k
The error message I get from CMD, is as follows:
C:\New>curl https://api.smartsheet.com/2.0/sheets/7654838910642052/columns/4 -H "Authorization: Bearer 5cn0otb4tdjueqzuflgnkzff17" -X PUT -d '{"title"
:"Weekend Date","index":4, "type" : "PICKLIST", "options" :["31-OCT-2015"]}' -k
{"errorCode":1124,"message":"Invalid Content-Type header. Media type not supported."}curl: (6) Could not resolve host: type; Host not found
¶hA▓╔ôÒ±$═»ù0♠~¡lk§☺▄ÜQ­K¡^ Õf ƒîa♀ÛæçÂ"õ8Ê╝±↕åÊJcurl: (6) Could not resolve host: PICKLIST,; Host not found
curl: (6) Could not resolve host: options; Host not found
curl: (3) [globbing] error: bad range specification after pos 3
Would appreciate any help I can get!!! This error is really annoying, and I have spent a good few hours trying to fix it.
** Note that I have changed the access token for security reasons, but the token I am using is definitely valid **
As Joseph suggested in his answer, you'll certainly want to verify that the value you're specifying for {columnId} in the URL is valid. However, the error you're getting is likely unrelated to that issue.
What's likely happening is that cURL is automatically setting the Content-Type header for you to the value "application/x-www-form-urlcoded" -- which is not a valid content type for this request to Smartsheet. You can resolve this error by simply setting the Content-Type header yourself in the request (i.e., add this: -H "Content-Type: application/json" to the request).
For example, my request to update the picklist options for a column such that the only option is "31-OCT-2015" looks like this:
curl https://api.smartsheet.com/2.0/sheets/{sheetId}/columns/{columnId} -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" -X PUT -d "{\"type\":\"PICKLIST\", \"options\":[\"31-OCT-2015\"]}" -k
Note that to update picklist options, the only attributes I need to set in the JSON are type and options. Also note that I used (escaped) double quotes in the JSON instead of single quotes -- you may or may not need to do this (depending on your platform).
It looks like the path you're using may be incorrect. I can see there's a "4" included in the path where the Column ID should be. For updating Column(s), you'd use the following path:
curl
https://api.smartsheet.com/2.0/sheets/{sheetId}/columns/{columnId}
You can find the API reference here.

POST json returns 400 with curl but functional test working

I am trying to build the POST of an API using Symfony2 and FOSRestBundle. The following functional test returns OK.
public function testPostArticleAction(){
$this->client->request(
'POST',
'/api/v1/articles.json',
array(),
array(),
array('CONTENT_TYPE' => 'application/json'),
'{"articleContent":"The content of the content"}'
);
$response = $this->client->getResponse();
$this->assertJsonResponse($response,201, false);
}
But when I try to send a request via Curl with the same request body, it gives me a 400 invalid json message:
{"code":400,"message":"Invalid json message received"}
Here are the curl commands I have tried:
curl -X POST -d '{"articleContent":"title1"}'
http://localhost:8000/api/v1/articles --header
"Content-type:application/json"
curl -X POST -d '{"articleContent":"title1"}'
http://localhost:8000/api/v1/articles.json
Please to note that the GET returns to me a json like:
{"id":68,"article_content":"contents contents"}
But my field is articleContent in my doctrine mapping file. What am I missing?
Your help is much appreciated.
Try updating your header option to:
"Content-Type: application/json"
Additionally - does this request require any type of authentication? You'd need to pass in an auth cookie if so.

Restler3: DELETE Body JSON

I really don't understand what I should do to make a DELETE request.
I want to use JSON as in/output only, so also a DELETE request should receive JSON.
But that doesn't make the goal:
public function delete($request_data = NULL)
$request_data is nil every time. I'm trying it by using cURL:
curl -X DELETE http://…/API/index.php/test.json -H "Content-Type: application/json" -d '{"key":"test","value":"1337"}'
Can someone explain that to me?

Categories