paypal subscription pipeline

alex313962
Contributor
Contributor

Hi, i'm trying to create a subscription via REST api. I succesfully retrieved my token, then i tried to add the product but if i try from php it retrieve 401 error, and via postman it says "UNSUPPORTED_MEDIA_TYPE". i don't understand if i need to create some other things before product, or if this passage is mandatory in order to make the user subscribe to my subscription. 
this is my php code, i'm using symfony6.0 

alex313962_0-1645818023885.png

any advice will be helpful, thanks to all

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

Nexus_Software
Contributor
Contributor

This works.

cur_product.PNG

 

You could test with the following PHP. Just replace YOUR_BEARER_TOKEN with your own Bearer token.

 

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api-m.sandbox.paypal.com/v1/catalogs/products',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
  "name": "Video Streaming Service",
  "description": "Video streaming service",
  "type": "SERVICE",
  "category": "SOFTWARE",
  "image_url": "https://example.com/streaming.jpg",
  "home_url": "https://example.com/home"

}',
  CURLOPT_HTTPHEADER => array(
    'Accept-Language: en_US',
    'Accept: application/json',
    'Authorization: Bearer YOUR_BEARER_TOKEN',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

 

 

 

 

 

View solution in original post

Login to Me Too
5 REPLIES 5

Nexus_Software
Contributor
Contributor

Hello @alex313962 ,

 

Can you try using Content-Type: application/json?

 

Thank you.

 

 

Powered by Custom Software : NexWebSites.com
PayPal Developers

Login to Me Too

alex313962
Contributor
Contributor

Hi, at first i tried with application/josn, after that i found a stackoverflow that suggest me to use this. it doesn't work in both cases

Login to Me Too
Solved

Nexus_Software
Contributor
Contributor

This works.

cur_product.PNG

 

You could test with the following PHP. Just replace YOUR_BEARER_TOKEN with your own Bearer token.

 

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api-m.sandbox.paypal.com/v1/catalogs/products',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
  "name": "Video Streaming Service",
  "description": "Video streaming service",
  "type": "SERVICE",
  "category": "SOFTWARE",
  "image_url": "https://example.com/streaming.jpg",
  "home_url": "https://example.com/home"

}',
  CURLOPT_HTTPHEADER => array(
    'Accept-Language: en_US',
    'Accept: application/json',
    'Authorization: Bearer YOUR_BEARER_TOKEN',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

 

 

 

 

 

Login to Me Too

alex313962
Contributor
Contributor

thank you! it works perfectly

Login to Me Too

Nexus_Software
Contributor
Contributor

You're welcome. Excellent👍. I'm glad to hear it's working for you.

 

 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.