austinfx
asked on
API help how to send one per line per the api documents
Hello I am trying to submit URLs to an API.
Their API states:
Links String[] Yes Uploaded to the POSTs Request Body. Every link must be on a new line. Minimum of 10 links without BatchID.
Here is the API Link: API DOCS
When I submit to the API it seems that only the first url is actually making it through.
Here is my code:
so I seem to be doing something wrong. Any ideas?
Their API states:
Links String[] Yes Uploaded to the POSTs Request Body. Every link must be on a new line. Minimum of 10 links without BatchID.
Here is the API Link: API DOCS
When I submit to the API it seems that only the first url is actually making it through.
Here is my code:
public function linklicious_upload_links($key)
{
if ($key == LINKLICIOUS_CRON_KEY)
{
$links = Linklicious::whereStatus(false)->get(['url'])->toArray();
if (!empty($links))
{
$links = implode('\n', array_flatten($links));
// dd(@$links);
$batchId = "9b1288b2-08d0-4753-85bb-TEST";
$batchName = "test";
$url = LINKLICIOUS_API_UPLOAD_LINKS . "?AppId=" . LINKLICIOUS_APP_ID . "&ApiKey=" . LINKLICIOUS_API_KEY . "&LinksPerDay=" . LINKLICIOUS_LINKS_PER_DAY . "&BatchName=" . $batchName . "&BatchId=". $batchId;
$params = array('http' => array('method' => 'POST', 'content' => $links));
$ctx = @stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
$response = @stream_get_contents($fp);
Log::info("Linklicious : Upload links triggered...");
Log::info("Response : " . $response);
} else
Log::info("Linklicious : No links available to upload...");
} else
{
Log::info("Linklicious : Invalid key...");
}
}
so I seem to be doing something wrong. Any ideas?
Did you try making your implode to use "\r\n" instead of just the "\n" ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
BLESS YOU BROTHER!!!!!!!!!!! THAT was IT!!
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for austinfx's comment #a40739387
Assisted answer: 500 points for Frank Pennock's comment #a40739249
for the following reason:
Thank you good sir!
Accepted answer: 0 points for austinfx's comment #a40739387
Assisted answer: 500 points for Frank Pennock's comment #a40739249
for the following reason:
Thank you good sir!
Very welcome! It happens all the time, and I know I've done it before...